-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
extension/tests/utils/resolveAzureDevOpsIdentities.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { isHostedAzureDevOps, resolveAzureDevOpsIdentities } from "../../task/utils/resolveAzureDevOpsIdentities"; | ||
import { describe } from "node:test"; | ||
import axios from "axios"; | ||
|
||
describe("isHostedAzureDevOps", () => { | ||
it("Old visualstudio url is hosted.", () => { | ||
const url = new URL("https://example.visualstudio.com/abc") | ||
const result = isHostedAzureDevOps(url); | ||
|
||
expect(result).toBeTruthy(); | ||
}); | ||
it("Dev Azure url is hosted.", () => { | ||
const url = new URL("https://dev.azure.com/example") | ||
const result = isHostedAzureDevOps(url); | ||
|
||
expect(result).toBeTruthy(); | ||
}); | ||
it("private url is not hosted.", () => { | ||
const url = new URL("https://tfs.example.com/tfs/Collection") | ||
const result = isHostedAzureDevOps(url); | ||
|
||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
|
||
jest.mock('axios'); | ||
const mockedAxios = axios as jest.Mocked<typeof axios>; | ||
|
||
const aliceOnPrem = { | ||
id: "any id", | ||
email: "[email protected]", | ||
providerDisplayName: "Alice" | ||
} | ||
|
||
const aliceHostedId = "any Id" | ||
const aliceHosted = { | ||
descriptor: "aad." + Buffer.from(aliceHostedId, 'utf8').toString('base64'), | ||
email: "[email protected]", | ||
providerDisplayName: "Alice" | ||
} | ||
|
||
describe("resolveAzureDevOpsIdentities", () => { | ||
it("No email input, is directly returned.", async () => { | ||
const url = new URL("https://example.visualstudio.com/abc") | ||
|
||
const input = ["be9321e2-f404-4ffa-8d6b-44efddb04865"]; | ||
const results = await resolveAzureDevOpsIdentities(url, input); | ||
|
||
const outputs = results.map(identity => identity.id); | ||
expect(outputs).toHaveLength(1); | ||
expect(outputs).toContain(input[0]); | ||
}); | ||
it("successfully resolve id for azure devops server", async () => { | ||
const url = new URL("https://example.onprem.com/abc") | ||
|
||
// Provide the data object to be returned | ||
mockedAxios.get.mockResolvedValue({ | ||
data: { | ||
count: 1, | ||
value: [aliceOnPrem], | ||
}, | ||
status: 200, | ||
}); | ||
|
||
const input = [aliceOnPrem.email]; | ||
const results = await resolveAzureDevOpsIdentities(url, input); | ||
|
||
const outputs = results.map(identity => identity.id); | ||
expect(outputs).toHaveLength(1); | ||
expect(outputs).toContain(aliceOnPrem.id); | ||
}); | ||
it("successfully resolve id for hosted azure devops", async () => { | ||
const url = new URL("https://dev.azure.com/exampleorganization") | ||
|
||
|
||
// Provide the data object to be returned | ||
mockedAxios.post.mockResolvedValue({ | ||
data: { | ||
count: 1, | ||
value: [aliceHosted], | ||
}, | ||
status: 200, | ||
}); | ||
|
||
const input = [aliceHosted.email]; | ||
const results = await resolveAzureDevOpsIdentities(url, input); | ||
|
||
const outputs = results.map(identity => identity.id); | ||
expect(outputs).toHaveLength(1); | ||
expect(outputs).toContain(aliceHostedId); | ||
}); | ||
}); |