Skip to content

Commit 7909449

Browse files
feat: enhance Jest environment and tests with DPoP key handling methods
1 parent 920bf99 commit 7909449

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

jest.environment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import JSDOMEnvironment from 'jest-environment-jsdom';
22
import fetch, { Headers, Request, Response } from 'node-fetch';
3+
import { TextEncoder, TextDecoder } from 'util';
34

45
/**
56
* Custom Jest Environment based on JSDOMEnvironment to support TextEncoder and TextDecoder.
@@ -18,6 +19,8 @@ export default class CustomJSDOMEnvironment extends JSDOMEnvironment {
1819
this.global.Headers = Headers;
1920
this.global.Request = Request;
2021
this.global.Response = Response;
22+
this.global.TextEncoder = TextEncoder;
23+
this.global.TextDecoder = TextDecoder;
2124
}
2225
}
2326

src/platforms/native/adapters/__tests__/NativeAuth0Client.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ describe('NativeAuth0Client', () => {
3434
saveCredentials: jest.fn().mockResolvedValue(undefined),
3535
hasValidCredentials: jest.fn().mockResolvedValue(true),
3636
clearCredentials: jest.fn().mockResolvedValue(undefined),
37+
clearDPoPKey: jest.fn().mockResolvedValue(undefined),
3738
resumeWebAuth: jest.fn().mockResolvedValue(undefined),
39+
getDPoPHeaders: jest.fn().mockResolvedValue({} as any),
3840
};
3941

4042
// Set up the mock implementation with a proper prototype
@@ -107,7 +109,8 @@ describe('NativeAuth0Client', () => {
107109
expect(mockBridgeInstance.initialize).toHaveBeenCalledWith(
108110
options.clientId,
109111
options.domain,
110-
undefined // No local auth options provided in this test
112+
undefined, // No local auth options provided in this test
113+
true // useDPoP defaults to true
111114
);
112115

113116
// Use client to avoid unused variable warning
@@ -127,7 +130,8 @@ describe('NativeAuth0Client', () => {
127130
expect(mockBridgeInstance.initialize).toHaveBeenCalledWith(
128131
options.clientId,
129132
options.domain,
130-
localAuthOptions
133+
localAuthOptions,
134+
true // useDPoP defaults to true
131135
);
132136

133137
// Use client to avoid unused variable warning

src/platforms/native/adapters/__tests__/NativeCredentialsManager.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const mockBridge: jest.Mocked<INativeBridge> = {
88
getCredentials: jest.fn(),
99
hasValidCredentials: jest.fn(),
1010
clearCredentials: jest.fn(),
11+
clearDPoPKey: jest.fn(),
1112
// Add stubs for other INativeBridge methods to satisfy the type.
1213
initialize: jest.fn(),
1314
hasValidInstance: jest.fn(),
@@ -16,6 +17,7 @@ const mockBridge: jest.Mocked<INativeBridge> = {
1617
clearSession: jest.fn(),
1718
cancelWebAuth: jest.fn(),
1819
resumeWebAuth: jest.fn(),
20+
getDPoPHeaders: jest.fn(),
1921
};
2022

2123
describe('NativeCredentialsManager', () => {

0 commit comments

Comments
 (0)