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

test: update unit tests to match new behaviour from PR#811 #813

Merged
merged 2 commits into from
Apr 15, 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@
},
{
"path": "recipe/session/index.js",
"limit": "19.1kb"
"limit": "19.2kb"
},
{
"path": "recipe/session/prebuiltui.js",
"limit": "22kb"
"limit": "22.1kb"
},
{
"path": "recipe/thirdpartyemailpassword/index.js",
Expand Down Expand Up @@ -181,7 +181,7 @@
},
{
"path": "recipe/thirdparty/prebuiltui.js",
"limit": "45kb"
"limit": "46kb"
},
{
"path": "recipe/emailpassword/prebuiltui.js",
Expand Down
12 changes: 9 additions & 3 deletions test/unit/recipe/session/sessionAuth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SessionContext from "../../../../lib/ts/recipe/session/sessionContext";
import { SessionContextType } from "../../../../lib/ts/recipe/session";
import { PrimitiveClaim, SessionClaim, useClaimValue } from "../../../../lib/ts/recipe/session";
import * as utils from "supertokens-web-js/utils";
import { WindowHandlerReference } from "supertokens-web-js/utils/windowHandler";

const TestClaim: SessionClaim<string> = new PrimitiveClaim({
id: "st-test-claim",
Expand Down Expand Up @@ -71,6 +72,10 @@ jest.spyOn(SuperTokens, "getInstanceOrThrow").mockImplementation(
({
redirectToAuth: (mockRedirectToAuth = jest.fn()),
redirectToUrl: (mockRedirectToUrl = jest.fn()),
appInfo: {
websiteDomain: { getAsStringDangerous: () => "http://localhost:3000" },
apiDomain: { getAsStringDangerous: () => "http://localhost:3001" },
},
} as any)
);
jest.spyOn(Session, "getInstanceOrThrow").mockImplementation(() => MockSession as any);
Expand All @@ -83,6 +88,7 @@ describe("SessionAuth", () => {
beforeEach(() => {
jest.clearAllMocks();
SuperTokens.reset();
WindowHandlerReference.init();

setMockResolves({
userId: "mock-user-id",
Expand Down Expand Up @@ -504,10 +510,10 @@ describe("SessionAuth", () => {
);

// then
expect(await result.findByText(/^accessTokenPayload:/)).toHaveTextContent(
`accessTokenPayload: ${JSON.stringify(mockAccessTokenPayload)}`
);
// it shouldn't update the context
expect(accessTokenPayloadElement).toHaveTextContent(`accessTokenPayload: ${JSON.stringify({})}`);

// and call redirect
expect(mockRedirectToUrl).toHaveBeenLastCalledWith("/test-redirect", undefined);
});

Expand Down
22 changes: 3 additions & 19 deletions test/unit/recipe/thirdparty/thirdParty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("ThirdParty", function () {
providers: [{} as any],
},
}).authReact(SuperTokens.getInstanceOrThrow().appInfo, false),
{ message: "Custom provider config should contain id and name attributes" }
{ message: "Custom provider config should contain an id attribute" }
);
});

Expand All @@ -159,23 +159,7 @@ describe("ThirdParty", function () {
],
},
}).authReact(SuperTokens.getInstanceOrThrow().appInfo, false),
{ message: "Custom provider config should contain id and name attributes" }
);
});

it("Initializing ThirdParty with Custom provider with empty config should throw", async function () {
assert.throws(
() =>
ThirdParty.init({
signInAndUpFeature: {
providers: [
{
id: "twitch",
} as any,
],
},
}).authReact(SuperTokens.getInstanceOrThrow().appInfo, false),
{ message: "Custom provider config should contain id and name attributes" }
{ message: "Custom provider config should contain an id attribute" }
);
});

Expand Down Expand Up @@ -308,7 +292,7 @@ describe("ThirdParty", function () {
providers: [Google.init(), Github.init(), "facebook" as any],
},
}).authReact(SuperTokens.getInstanceOrThrow().appInfo, false),
{ message: "Custom provider config should contain id and name attributes" }
{ message: "Custom provider config should contain an id attribute" }
);
});

Expand Down
Loading