Skip to content

test(e2e): add test for getToken with custom JWT templates#8053

Open
tmilewski wants to merge 3 commits intomainfrom
tom/user-4952-test-against-skipcache-and-custom-jwts
Open

test(e2e): add test for getToken with custom JWT templates#8053
tmilewski wants to merge 3 commits intomainfrom
tom/user-4952-test-against-skipcache-and-custom-jwts

Conversation

@tmilewski
Copy link
Member

@tmilewski tmilewski commented Mar 12, 2026

Description

  • Adds a Playwright integration test verifying getToken({ template }) returns valid custom JWT tokens via a Next.js App Router API route
  • Creates a temporary JWT template with a custom claim, signs in a user, and asserts getToken return tokens with the expected test_claim payload

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other: Test

Summary by CodeRabbit

  • Tests

    • Added integration test for custom JWT template validation.
  • Chores

    • Added changeset metadata file.

@tmilewski tmilewski self-assigned this Mar 12, 2026
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 1a5cf77

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 12, 2026 10:09pm

Request Review

@tmilewski tmilewski changed the title test(integration): add e2e test for getToken with custom JWT templates and skipCache test(e2e): add test for getToken with custom JWT templates and skipCache Mar 12, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8053

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8053

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8053

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8053

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8053

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8053

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8053

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8053

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8053

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8053

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8053

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8053

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8053

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8053

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8053

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8053

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8053

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8053

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8053

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8053

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8053

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8053

commit: 1a5cf77

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: ef613eca-68da-4f6d-8041-93c3027ad52c

📥 Commits

Reviewing files that changed from the base of the PR and between a017154 and 1a5cf77.

📒 Files selected for processing (1)
  • integration/tests/custom-jwt.test.ts

📝 Walkthrough

Walkthrough

This pull request adds a changeset marker file and introduces a new integration test for custom JWT templates. The changeset file (.changeset/dull-breads-watch.md) was created as an empty YAML document. The integration test (custom-jwt.test.ts) validates a complete custom JWT template workflow in a Next.js environment, including setting up a test app, creating a JWT template, authenticating a user via UI, and verifying the custom JWT token claims and issued-at timestamps across multiple token requests.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'test(e2e): add test for getToken with custom JWT templates' directly and clearly describes the main change—adding an integration test for getToken with custom JWT templates, which matches the new test file integration/tests/custom-jwt.test.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.


const payload2 = JSON.parse(atob(body2.customToken.split('.')[1]));
expect(payload2.test_claim).toBe('hello_from_e2e');
expect(payload2.iat).toBeGreaterThanOrEqual(payload1.iat);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a strong enough assertion to know that we got a freshly minted token with skipCache?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved, but defer to jacek

Copy link
Member

@jacekradko jacekradko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, even though I think we can iterate on this a little bit. For one, we should prove caching works — call fetchToken(false) twice, assert tokens are equal, then fetchToken(true) and assert it differs. The iat assertion can be stronger to not give false positives.

@tmilewski
Copy link
Member Author

Overall looks good, even though I think we can iterate on this a little bit. For one, we should prove caching works — call fetchToken(false) twice, assert tokens are equal, then fetchToken(true) and assert it differs. The iat assertion can be stronger to not give false positives.

@jacekradko I think I accidentally removed my initial call. You're absolutely right.

@tmilewski tmilewski changed the title test(e2e): add test for getToken with custom JWT templates and skipCache test(e2e): add test for getToken with custom JWT templates Mar 12, 2026
@tmilewski
Copy link
Member Author

Overall looks good, even though I think we can iterate on this a little bit. For one, we should prove caching works — call fetchToken(false) twice, assert tokens are equal, then fetchToken(true) and assert it differs. The iat assertion can be stronger to not give false positives.

@jacekradko So, getToken with a custom template never caches. As such, I updated the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants