<commit_before>import { expect } from "chai";
import { Authority, AuthorityType } from "../../src/authority/Authority";
import { ClientConfigurationErrorMessage } from "../../src/error/ClientConfigurationError"
import { TEST_CONFIG } from "../TestConstants";

class testAuthority extends Authority{
    public constructor(authority: string, validateAuthority: boolean) {
        super(authority, validateAuthority);
    }

    public get AuthorityType(): AuthorityType {
        return AuthorityType.Aad;
    }

    public async GetOpenIdConfigurationEndpointAsync(): Promise<string> {
        return this.DefaultOpenIdConfigurationEndpoint;
    }
}

let authority: testAuthority;

describe("Authority.ts Class", function () {
    beforeEach(function() {
        authority = new testAuthority(TEST_CONFIG.validAuthority, false);
    });

    afterEach(function () {
        authority = null;
    });

    it("tests initialization of Authority", function() {

        expect(authority).to.be.instanceOf(testAuthority);
        expect(authority.AuthorityType).to.be.equal(AuthorityType.Aad);
    });

    it("throws error if ResolveEndpointsAsync hasn't been called yet", function () {
        try {
            const authEndpoint = authority.AuthorizationEndpoint
        }
        catch(e) {
            expect(e).to.be.equal("Please call ResolveEndpointsAsync first");
        }
    });

    it("tests EndSessionEndpoint", async function () {
        const response = await authority.resolveEndpointsAsync();
        const endSessionEndpoint = response.EndSessionEndpoint

        expect(response).to.be.instanceOf(testAuthority);
        expect(endSessionEndpoint).to.contain(response.Tenant)
    });

    it("tests SelfSignedJwtAudience", async function () {
        const response = await authority.resolveEndpointsAsync();
        const selfSignedJwtAudience = response.SelfSignedJwtAudience

        expect(response).to.be.instanceOf(testAuthority);
        expect(selfSignedJwtAudience).to.contain(response.Tenant)
    });

    it("throws invalidAuthorityType on init if authority is not url", function () {
        try {
            authority = new testAuthority("not a url", false);
        }
        catch(e) {
            expect(e).to.be.equal(ClientConfigurationErrorMessage.authorityUriInsecure)
        }
    });

    it("throws authorityUriInsecure on init if not https", function () {
        try {
            authority = new testAuthority("http://login.microsoftonline.com/common", false);
        }
        catch(e) {
            expect(e).to.be.equal(ClientConfigurationErrorMessage.authorityUriInsecure)
        }
    });

    it("throws authorityUriInvalidPath on init if there is no path", function () {
        try {
            authority = new testAuthority("https://login.microsoftonline.com", false);
        }
        catch(e) {
            expect(e).to.be.equal(ClientConfigurationErrorMessage.authorityUriInvalidPath)
        }
    });
    

});<commit_msg>Fix unit test<commit_after>import { expect } from "chai";
import { Authority, AuthorityType } from "../../src/authority/Authority";
import { ClientConfigurationErrorMessage } from "../../src/error/ClientConfigurationError"
import { TEST_CONFIG } from "../TestConstants";

class testAuthority extends Authority{
    public constructor(authority: string, validateAuthority: boolean) {
        super(authority, validateAuthority);
    }

    public get AuthorityType(): AuthorityType {
        return AuthorityType.Aad;
    }

    public async GetOpenIdConfigurationEndpointAsync(): Promise<string> {
        return this.DefaultOpenIdConfigurationEndpoint;
    }
}

let authority: testAuthority;

describe("Authority.ts Class", function () {
    beforeEach(function() {
        authority = new testAuthority(TEST_CONFIG.validAuthority, false);
    });

    afterEach(function () {
        authority = null;
    });

    it("tests initialization of Authority", function() {

        expect(authority).to.be.instanceOf(testAuthority);
        expect(authority.AuthorityType).to.be.equal(AuthorityType.Aad);
    });

    it("throws error if ResolveEndpointsAsync hasn't been called yet", function () {
        try {
            const authEndpoint = authority.AuthorizationEndpoint
        }
        catch(e) {
            expect(e).to.be.equal("Please call ResolveEndpointsAsync first");
        }
    });

    it("tests EndSessionEndpoint", async function () {
        const response = await authority.resolveEndpointsAsync();
        const endSessionEndpoint = response.EndSessionEndpoint

        expect(response).to.be.instanceOf(testAuthority);
        expect(endSessionEndpoint).to.contain(response.Tenant)
    });

    it("tests SelfSignedJwtAudience", async function () {
        const response = await authority.resolveEndpointsAsync();
        const selfSignedJwtAudience = response.SelfSignedJwtAudience

        expect(response).to.be.instanceOf(testAuthority);
        expect(selfSignedJwtAudience).to.contain(response.Tenant)
    });

    it("throws invalidAuthorityType on init if authority is not url", function () {
        try {
            authority = new testAuthority("", false);
        }
        catch(e) {
            expect(e).to.be.equal(ClientConfigurationErrorMessage.invalidAuthorityType)
        }
    });

    it("throws authorityUriInsecure on init if not https", function () {
        try {
            authority = new testAuthority("http://login.microsoftonline.com/common", false);
        }
        catch(e) {
            expect(e).to.be.equal(ClientConfigurationErrorMessage.authorityUriInsecure)
        }
    });

    it("throws authorityUriInvalidPath on init if there is no path", function () {
        try {
            authority = new testAuthority("https://login.microsoftonline.com", false);
        }
        catch(e) {
            expect(e).to.be.equal(ClientConfigurationErrorMessage.authorityUriInvalidPath)
        }
    });
    

});
{'fraction_non_alphanumeric': 0.11098072087175188, 'fraction_numerical': 0.0, 'mean_word_length': 2.9327620303230058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6029840', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1562, 'n_words': 312}