Skip to content

Commit

Permalink
Add test for core being down and error handler called in next
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Oct 7, 2024
1 parent d3ef4b4 commit c4868b8
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions test/nextjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,30 +958,37 @@ if (major >= 18) {
}
});

// it("should go to next error handler when withSession is called without core", async function () {
// const tokens = await getValidTokensAfterSignup({ tokenTransferMethod: "header" });

// const authenticatedRequest = new NextRequest("http://localhost:3000/api/get-user", {
// headers: {
// Cookie: `sAccessToken=${tokens.access}`,
// },
// });

// // Manually kill to get error when withSession is called
// await killAllSTCoresOnly();

// const authenticatedResponse = await withSession(authenticatedRequest, async (err, session) => {
// if (err) return NextResponse.json(`CUSTOM_ERROR: ${err}`, { status: 500 });
// return NextResponse.json({
// userId: session.getUserId(),
// sessionHandle: session.getHandle(),
// accessTokenPayload: session.getAccessTokenPayload(),
// });
// });
// const responseJSON = await authenticatedResponse.json();
// console.log(responseJSON);
// assert.strictEqual(responseJSON, {}, "test");
// });
it("should go to next error handler when withSession is called without core", async function () {
const tokens = await getValidTokensAfterSignup({ tokenTransferMethod: "header" });

const authenticatedRequest = new NextRequest("http://localhost:3000/api/get-user", {
headers: {
Cookie: `sAccessToken=${tokens.access}`,
},
});

// Manually kill to get error when withSession is called
await killAllSTCoresOnly();

const authenticatedResponse = await withSession(
authenticatedRequest,
async (err, session) => {
if (err) return NextResponse.json(`CUSTOM_ERROR: ${err}`, { status: 500 });
return NextResponse.json({
userId: session.getUserId(),
sessionHandle: session.getHandle(),
accessTokenPayload: session.getAccessTokenPayload(),
});
},
{ checkDatabase: true }
);
const responseJSON = await authenticatedResponse.json();
assert.strictEqual(
responseJSON,
"CUSTOM_ERROR: Error: No SuperTokens core available to query",
"should return custom error from next error handler"
);
});
});

describe("session refresh test", async () => {
Expand Down

0 comments on commit c4868b8

Please sign in to comment.