-
Notifications
You must be signed in to change notification settings - Fork 8
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
9 changed files
with
224 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,149 @@ | ||
import { setupJest } from "../mocks/server"; | ||
import { ArgosApiClient, createArgosApiClient } from "./api-client"; | ||
import { | ||
ArgosApiClient, | ||
createArgosApiClient, | ||
getBearerToken, | ||
} from "./api-client"; | ||
|
||
setupJest(); | ||
|
||
let apiClient: ArgosApiClient; | ||
beforeAll(() => { | ||
apiClient = createArgosApiClient({ | ||
baseUrl: "https://api.argos-ci.dev", | ||
token: "92d832e0d22ab113c8979d73a87a11130eaa24a9", | ||
|
||
describe("#createArgosApiClient", () => { | ||
beforeAll(() => { | ||
apiClient = createArgosApiClient({ | ||
baseUrl: "https://api.argos-ci.dev", | ||
bearerToken: "Bearer 92d832e0d22ab113c8979d73a87a11130eaa24a9", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#createBuild", () => { | ||
it("creates build", async () => { | ||
const result = await apiClient.createBuild({ | ||
commit: "f16f980bd17cccfa93a1ae7766727e67950773d0", | ||
screenshotKeys: ["123", "456"], | ||
}); | ||
expect(result).toEqual({ | ||
build: { | ||
id: "123", | ||
url: "https://app.argos-ci.dev/builds/123", | ||
}, | ||
screenshots: [ | ||
{ | ||
key: "123", | ||
putUrl: "https://api.s3.dev/upload/123", | ||
describe("#createBuild", () => { | ||
it("creates build", async () => { | ||
const result = await apiClient.createBuild({ | ||
commit: "f16f980bd17cccfa93a1ae7766727e67950773d0", | ||
screenshotKeys: ["123", "456"], | ||
}); | ||
expect(result).toEqual({ | ||
build: { | ||
id: "123", | ||
url: "https://app.argos-ci.dev/builds/123", | ||
}, | ||
{ | ||
key: "456", | ||
putUrl: "https://api.s3.dev/upload/456", | ||
screenshots: [ | ||
{ | ||
key: "123", | ||
putUrl: "https://api.s3.dev/upload/123", | ||
}, | ||
{ | ||
key: "456", | ||
putUrl: "https://api.s3.dev/upload/456", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#updateBuild", () => { | ||
it("updates build", async () => { | ||
const result = await apiClient.updateBuild({ | ||
buildId: "123", | ||
screenshots: [ | ||
{ key: "123", name: "screenshot 1" }, | ||
{ key: "456", name: "screenshot 2" }, | ||
], | ||
}); | ||
expect(result).toEqual({ | ||
build: { | ||
id: "123", | ||
url: "https://app.argos-ci.dev/builds/123", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#updateBuild", () => { | ||
it("updates build", async () => { | ||
const result = await apiClient.updateBuild({ | ||
buildId: "123", | ||
screenshots: [ | ||
{ key: "123", name: "screenshot 1" }, | ||
{ key: "456", name: "screenshot 2" }, | ||
], | ||
}); | ||
expect(result).toEqual({ | ||
build: { | ||
id: "123", | ||
url: "https://app.argos-ci.dev/builds/123", | ||
}, | ||
describe("#getBearerToken", () => { | ||
describe("without CI", () => { | ||
describe("without token", () => { | ||
it("should throw", () => { | ||
const config = {}; | ||
expect(() => getBearerToken(config)).toThrow( | ||
"Missing Argos repository token 'ARGOS_TOKEN'" | ||
); | ||
}); | ||
}); | ||
|
||
describe("with token", () => { | ||
it("should return bearer token", () => { | ||
const config = { token: "this-token" }; | ||
expect(getBearerToken(config)).toBe(`Bearer this-token`); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with unknown CI", () => { | ||
const configProps = { ciService: "unknownCI" }; | ||
|
||
describe("without token", () => { | ||
it("should throw", () => { | ||
const config = { ...configProps }; | ||
expect(() => getBearerToken(config)).toThrow( | ||
"Missing Argos repository token 'ARGOS_TOKEN'" | ||
); | ||
}); | ||
}); | ||
|
||
describe("with token", () => { | ||
it("should return bearer token", () => { | ||
const config = { ...configProps, token: "this-token" }; | ||
expect(getBearerToken(config)).toBe(`Bearer this-token`); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with Github Actions CI", () => { | ||
const configProps = { ciService: "GitHub Actions" }; | ||
|
||
describe("with token", () => { | ||
it("should return bearer token", () => { | ||
const config = { ...configProps, token: "this-token" }; | ||
expect(getBearerToken(config)).toBe(`Bearer this-token`); | ||
}); | ||
}); | ||
|
||
describe("without token but with CI env variables", () => { | ||
it("should return a composite token", () => { | ||
const config = { | ||
...configProps, | ||
owner: "this-owner", | ||
repository: "this-repository", | ||
jobId: "this-jobId", | ||
}; | ||
|
||
const base64 = Buffer.from( | ||
JSON.stringify({ | ||
owner: config.owner, | ||
repository: config.repository, | ||
jobId: config.jobId, | ||
}), | ||
"utf8" | ||
).toString("base64"); | ||
|
||
const bearerToken = getBearerToken(config); | ||
|
||
expect(bearerToken).toBe(`Bearer tokenless-github-${base64}`); | ||
expect(bearerToken).toBe( | ||
"Bearer tokenless-github-eyJvd25lciI6InRoaXMtb3duZXIiLCJyZXBvc2l0b3J5IjoidGhpcy1yZXBvc2l0b3J5Iiwiam9iSWQiOiJ0aGlzLWpvYklkIn0=" | ||
); | ||
}); | ||
}); | ||
|
||
describe("without token and without CI env variables", () => { | ||
it("should throw", () => { | ||
const config = { ...configProps }; | ||
expect(() => getBearerToken(config)).toThrow( | ||
"Automatic GitHub Actions variables detection failed. Please add the 'ARGOS_TOKEN'" | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
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
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
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
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
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
Oops, something went wrong.