Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Aug 24, 2024
1 parent 3eb419d commit ee8c4c3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
18 changes: 18 additions & 0 deletions packages/core/mocks/handlers/getProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { http, HttpResponse } from "msw";

type GetProjectResponseBody = {
id: string;
defaultBaseBranch: string;
hasRemoteContentAccess: boolean;
};

export const getProject = http.get<never, never, GetProjectResponseBody>(
"https://api.argos-ci.dev/project",
async () => {
return HttpResponse.json({
id: "123",
defaultBaseBranch: "main",
hasRemoteContentAccess: true,
});
},
);
8 changes: 7 additions & 1 deletion packages/core/mocks/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { beforeAll, afterAll, afterEach } from "vitest";
import { setupServer } from "msw/node";
import { createBuild } from "./handlers/createBuild";
import { getProject } from "./handlers/getProject";
import { updateBuild } from "./handlers/updateBuild";
import { uploadScreenshot } from "./handlers/uploadScreenshot";

export const server = setupServer(createBuild, updateBuild, uploadScreenshot);
export const server = setupServer(
createBuild,
updateBuild,
uploadScreenshot,
getProject,
);

export const setupMockServer = () => {
beforeAll(() => server.listen());
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/api-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("#getAuthToken", () => {
describe("with token", () => {
it("should return bearer token", () => {
const config = { token: "this-token" };
expect(getAuthToken(config)).toBe(`Bearer this-token`);
expect(getAuthToken(config)).toBe(`this-token`);
});
});
});
Expand All @@ -110,7 +110,7 @@ describe("#getAuthToken", () => {
describe("with token", () => {
it("should return bearer token", () => {
const config = { ...configProps, token: "this-token" };
expect(getAuthToken(config)).toBe(`Bearer this-token`);
expect(getAuthToken(config)).toBe(`this-token`);
});
});
});
Expand All @@ -121,7 +121,7 @@ describe("#getAuthToken", () => {
describe("with token", () => {
it("should return bearer token", () => {
const config = { ...configProps, token: "this-token" };
expect(getAuthToken(config)).toBe(`Bearer this-token`);
expect(getAuthToken(config)).toBe(`this-token`);
});
});

Expand All @@ -147,9 +147,9 @@ describe("#getAuthToken", () => {

const bearerToken = getAuthToken(config);

expect(bearerToken).toBe(`Bearer tokenless-github-${base64}`);
expect(bearerToken).toBe(`tokenless-github-${base64}`);
expect(bearerToken).toBe(
"Bearer tokenless-github-eyJvd25lciI6InRoaXMtb3duZXIiLCJyZXBvc2l0b3J5IjoidGhpcy1yZXBvc2l0b3J5Iiwiam9iSWQiOiJ0aGlzLWpvYklkIiwicnVuSWQiOiIxMjM0NSJ9",
"tokenless-github-eyJvd25lciI6InRoaXMtb3duZXIiLCJyZXBvc2l0b3J5IjoidGhpcy1yZXBvc2l0b3J5Iiwiam9iSWQiOiJ0aGlzLWpvYklkIiwicnVuSWQiOiIxMjM0NSJ9",
);
});
});
Expand Down

0 comments on commit ee8c4c3

Please sign in to comment.