Skip to content
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

feat: add auth to listBlueprints #14

Merged
merged 2 commits into from
Nov 20, 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
33 changes: 33 additions & 0 deletions integration_tests/blueprint.prod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,37 @@ describe("Blueprint prod test suite", () => {
const blueprint = await sdk().getBlueprint("Bisht13/SuccinctZKResidencyInvite:v1");
expect(blueprint.props.version).toBe(2);
});

test("Should only list blueprints not Done of logged in user", async () => {
const blueprints = await sdk({
baseUrl: "http://localhost:8080",
auth: {
getToken: async () =>
// Token only usable locally
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzQ2NzUyMjIsImdpdGh1Yl91c2VybmFtZSI6IkRpbWlEdW1vIn0.MqrxsUWt-f3rzg8rd_agovrgaEorMGcTL_PyeX4A7To",
onTokenExpired: async () => {},
},
}).listBlueprints({
status: [Status.Draft, Status.Done],
});

expect(blueprints.some((bp) => bp.props.status === Status.Failed)).toBeFalse();
expect(blueprints.some((bp) 1=> bp.props.status === Status.Draft)).toBeTrue();
expect(
blueprints.some((bp) => bp.props.id === "839eefd4-944e-419a-993a-dc7954b5b49a")
).toBeFalse();
expect(
blueprints.some((bp) => bp.props.id === "1e65293c-667b-4350-b9c0-1769c320662c")
).toBeTrue();
});

test("Should only list blueprints Done of logged out user", async () => {
const blueprints = await sdk({
baseUrl: "http://localhost:8080",
}).listBlueprints({
status: [Status.Draft, Status.Done],
});

expect(blueprints.some((bp) => bp.props.status === Status.Draft)).toBeFalse();
});
});
3 changes: 2 additions & 1 deletion src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ export class Blueprint {
try {
response = await get<{ blueprints?: BlueprintResponse[] }>(
`${baseUrl}/blueprint`,
requestOptions
requestOptions,
auth
);
} catch (err) {
console.error("Failed calling POST on /blueprint/ in submitDraft: ", err);
Expand Down