Skip to content

🩹 Fix hub test #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/hub/src/lib/who-am-i.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ describe("whoAmI", () => {
it("should fetch identity info", async () => {
const info = await whoAmI({ credentials: { accessToken: TEST_ACCESS_TOKEN }, hubUrl: TEST_HUB_URL });

if (info.auth.accessToken?.createdAt instanceof Date) {
info.auth.accessToken.createdAt = new Date(0);
}

assert.deepStrictEqual(info, {
type: "user",
id: "62f264b9f3c90f4b6514a269",
Expand All @@ -21,6 +25,7 @@ describe("whoAmI", () => {
auth: {
type: "access_token",
accessToken: {
createdAt: new Date(0),
displayName: "ci-hub.js",
role: "write",
},
Expand Down
14 changes: 4 additions & 10 deletions packages/hub/src/lib/who-am-i.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export interface AuthInfo {
type: AuthType;
accessToken?: {
displayName: string;
expiration?: Date;
role: AccessTokenRole;
createdAt: Date;
};
expiresAt?: Date;
}
Expand All @@ -79,17 +79,11 @@ export async function whoAmI(params: {
}

const response: ApiWhoAmIReponse & {
auth: Omit<AuthInfo, "accessToken"> & {
accessToken?: {
displayName: string;
expiration?: Date; // actually string but we fix it below
role: AccessTokenRole;
};
};
auth: AuthInfo;
} = await res.json();

if (typeof response.auth.accessToken?.expiration === "string") {
response.auth.accessToken.expiration = new Date(response.auth.accessToken.expiration);
if (typeof response.auth.accessToken?.createdAt === "string") {
response.auth.accessToken.createdAt = new Date(response.auth.accessToken.createdAt);
}

return response;
Expand Down
Loading