@workos-inc/authkit-nextjs 2.13.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.spec.ts CHANGED
@@ -3,23 +3,21 @@ import { redirectWithFallback, errorResponseWithFallback } from './utils.js';
3
3
 
4
4
  describe('utils', () => {
5
5
  afterEach(() => {
6
- jest.resetModules();
6
+ vi.resetModules();
7
+ vi.restoreAllMocks();
7
8
  });
8
9
 
9
10
  describe('redirectWithFallback', () => {
10
11
  it('uses NextResponse.redirect when available', () => {
11
12
  const redirectUrl = 'https://example.com';
12
- const mockRedirect = jest.fn().mockReturnValue('redirected');
13
- const originalRedirect = NextResponse.redirect;
13
+ const mockRedirect = vi.fn().mockReturnValue('redirected');
14
14
 
15
- NextResponse.redirect = mockRedirect;
15
+ vi.spyOn(NextResponse, 'redirect').mockImplementation(mockRedirect);
16
16
 
17
17
  const result = redirectWithFallback(redirectUrl);
18
18
 
19
19
  expect(mockRedirect).toHaveBeenCalledWith(redirectUrl, { headers: undefined });
20
20
  expect(result).toBe('redirected');
21
-
22
- NextResponse.redirect = originalRedirect;
23
21
  });
24
22
 
25
23
  it('uses headers when provided', () => {
@@ -35,9 +33,9 @@ describe('utils', () => {
35
33
  it('falls back to standard Response when NextResponse exists but redirect is undefined', async () => {
36
34
  const redirectUrl = 'https://example.com';
37
35
 
38
- jest.resetModules();
36
+ vi.resetModules();
39
37
 
40
- jest.mock('next/server', () => ({
38
+ vi.doMock('next/server', () => ({
41
39
  NextResponse: {
42
40
  // exists but has no redirect method
43
41
  },
@@ -55,10 +53,10 @@ describe('utils', () => {
55
53
  it('falls back to standard Response when NextResponse is undefined', async () => {
56
54
  const redirectUrl = 'https://example.com';
57
55
 
58
- jest.resetModules();
56
+ vi.resetModules();
59
57
 
60
58
  // Mock with undefined NextResponse
61
- jest.mock('next/server', () => ({
59
+ vi.doMock('next/server', () => ({
62
60
  NextResponse: undefined,
63
61
  }));
64
62
 
@@ -81,8 +79,8 @@ describe('utils', () => {
81
79
  };
82
80
 
83
81
  it('uses NextResponse.json when available', () => {
84
- const mockJson = jest.fn().mockReturnValue('error json response');
85
- NextResponse.json = mockJson;
82
+ const mockJson = vi.fn().mockReturnValue('error json response');
83
+ vi.spyOn(NextResponse, 'json').mockImplementation(mockJson);
86
84
 
87
85
  const result = errorResponseWithFallback(errorBody);
88
86
 
@@ -90,25 +88,10 @@ describe('utils', () => {
90
88
  expect(result).toBe('error json response');
91
89
  });
92
90
 
93
- it('falls back to standard Response when NextResponse is not available', () => {
94
- const originalJson = NextResponse.json;
95
-
96
- // @ts-expect-error - This is to test the fallback
97
- delete NextResponse.json;
98
-
99
- const result = errorResponseWithFallback(errorBody);
100
-
101
- expect(result).toBeInstanceOf(Response);
102
- expect(result.status).toBe(500);
103
- expect(result.headers.get('Content-Type')).toBe('application/json');
104
-
105
- NextResponse.json = originalJson;
106
- });
107
-
108
91
  it('falls back to standard Response when NextResponse exists but json is undefined', async () => {
109
- jest.resetModules();
92
+ vi.resetModules();
110
93
 
111
- jest.mock('next/server', () => ({
94
+ vi.doMock('next/server', () => ({
112
95
  NextResponse: {
113
96
  // exists but has no json method
114
97
  },
@@ -124,9 +107,9 @@ describe('utils', () => {
124
107
  });
125
108
 
126
109
  it('falls back to standard Response when NextResponse is undefined', async () => {
127
- jest.resetModules();
110
+ vi.resetModules();
128
111
 
129
- jest.mock('next/server', () => ({
112
+ vi.doMock('next/server', () => ({
130
113
  NextResponse: undefined,
131
114
  }));
132
115
 
@@ -1,9 +1,7 @@
1
- import { describe, it, expect, beforeEach, jest } from '@jest/globals';
2
-
3
1
  import { validateApiKey } from './validate-api-key.js';
4
2
  import { getWorkOS } from './workos.js';
5
3
 
6
- // These are mocked in jest.setup.ts
4
+ // These are mocked in vitest.setup.ts
7
5
  import { headers } from 'next/headers';
8
6
 
9
7
  const workos = getWorkOS();
@@ -11,7 +9,7 @@ const workos = getWorkOS();
11
9
  describe('validate-api-key.ts', () => {
12
10
  beforeEach(async () => {
13
11
  // Clear all mocks between tests
14
- jest.clearAllMocks();
12
+ vi.clearAllMocks();
15
13
 
16
14
  const nextHeaders = await headers();
17
15
  // @ts-expect-error - _reset is part of the mock
@@ -34,7 +32,7 @@ describe('validate-api-key.ts', () => {
34
32
  },
35
33
  };
36
34
 
37
- jest.spyOn(workos.apiKeys, 'validateApiKey').mockResolvedValue(mockApiKeyResponse);
35
+ vi.spyOn(workos.apiKeys, 'validateApiKey').mockResolvedValue(mockApiKeyResponse);
38
36
 
39
37
  const nextHeaders = await headers();
40
38
  nextHeaders.set('authorization', 'Bearer sk_test_1234567890');
@@ -97,7 +95,7 @@ describe('validate-api-key.ts', () => {
97
95
 
98
96
  it('should return { apiKey: null } when WorkOS validation fails', async () => {
99
97
  const mockResponse = { apiKey: null };
100
- jest.spyOn(workos.apiKeys, 'validateApiKey').mockResolvedValue(mockResponse);
98
+ vi.spyOn(workos.apiKeys, 'validateApiKey').mockResolvedValue(mockResponse);
101
99
 
102
100
  const nextHeaders = await headers();
103
101
  nextHeaders.set('authorization', 'Bearer invalid_key');
@@ -4,7 +4,7 @@ import { getWorkOS, VERSION } from './workos.js';
4
4
  describe('workos', () => {
5
5
  const workos = getWorkOS();
6
6
  beforeEach(() => {
7
- jest.clearAllMocks();
7
+ vi.clearAllMocks();
8
8
  });
9
9
 
10
10
  it('initializes WorkOS with the correct configuration', () => {
@@ -35,7 +35,7 @@ describe('workos', () => {
35
35
  const originalEnv = process.env;
36
36
 
37
37
  beforeEach(() => {
38
- jest.resetModules();
38
+ vi.resetModules();
39
39
  process.env = { ...originalEnv };
40
40
  });
41
41
 
package/src/workos.ts CHANGED
@@ -2,7 +2,7 @@ import { WorkOS } from '@workos-inc/node';
2
2
  import { WORKOS_API_HOSTNAME, WORKOS_API_KEY, WORKOS_API_HTTPS, WORKOS_API_PORT } from './env-variables.js';
3
3
  import { lazy } from './utils.js';
4
4
 
5
- export const VERSION = '2.13.0';
5
+ export const VERSION = '2.14.0';
6
6
 
7
7
  const options = {
8
8
  apiHostname: WORKOS_API_HOSTNAME,