Skip to content

chore(tests): corejs update and wrap fetchMock.restore()/reset() in arrow functions for… #1189

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
89 changes: 40 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@
"eslint-plugin-prettier": "^5.0.1",
"expo": "^52.0.40",
"faker": "^4.1.0",
"fetch-mock": "^7.3.9",
"fetch-mock": "^9.1.0",
"husky": "^4.2.5",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.5.0",
34 changes: 17 additions & 17 deletions src/auth/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ describe('auth', () => {
jest.useFakeTimers().setSystemTime(new Date('2023-01-01'));
});

beforeEach(fetchMock.restore);
beforeEach(() => fetchMock.restore());

describe('constructor', () => {
it('should build with domain', () => {
@@ -57,7 +57,7 @@ describe('auth', () => {
it('should fail without domain', () => {
expect(() => new Auth({ clientId })).toThrowErrorMatchingSnapshot();
});

it('should accept custom headers', () => {
const headers = { 'X-Custom-Header': 'custom-value' };
const auth = new Auth({ baseUrl, clientId, headers });
@@ -1061,48 +1061,48 @@ describe('auth', () => {
});

describe('method-specific custom headers', () => {
it('should accept and use custom headers in passwordRealm that don\'t conflict with defaults', async () => {
it("should accept and use custom headers in passwordRealm that don't conflict with defaults", async () => {
fetchMock.postOnce('https://samples.auth0.com/oauth/token', tokens);
const customHeaders = { 'X-Custom-Header': 'custom-value' };

await auth.passwordRealm({
username: '[email protected]',
password: 'secret pass',
realm: 'Username-Password-Authentication',
headers: customHeaders
headers: customHeaders,
});

const [_, fetchOptions] = fetchMock.lastCall();
expect(fetchOptions.headers.get('X-Custom-Header')).toBe('custom-value');
});
it('should accept and use custom headers in userInfo that don\'t conflict with defaults', async () => {

it("should accept and use custom headers in userInfo that don't conflict with defaults", async () => {
const success = {
status: 200,
body: { sub: 'auth0|1029837475' },
headers: { 'Content-Type': 'application/json' },
};
fetchMock.getOnce('https://samples.auth0.com/userinfo', success);
const customHeaders = { 'X-Custom-Header': 'custom-value' };
await auth.userInfo({

await auth.userInfo({
token: 'an access token of a user',
headers: customHeaders
headers: customHeaders,
});

const [_, fetchOptions] = fetchMock.lastCall();
expect(fetchOptions.headers.get('X-Custom-Header')).toBe('custom-value');
});
it('should accept and use custom headers in refreshToken that don\'t conflict with defaults', async () => {

it("should accept and use custom headers in refreshToken that don't conflict with defaults", async () => {
fetchMock.postOnce('https://samples.auth0.com/oauth/token', tokens);
const customHeaders = { 'X-Custom-Header': 'custom-value' };

await auth.refreshToken({
refreshToken: 'a refresh token of a user',
headers: customHeaders
headers: customHeaders,
});

const [_, fetchOptions] = fetchMock.lastCall();
expect(fetchOptions.headers.get('X-Custom-Header')).toBe('custom-value');
});
50 changes: 25 additions & 25 deletions src/management/__tests__/users.spec.js
Original file line number Diff line number Diff line change
@@ -3,12 +3,12 @@ import fetchMock from 'fetch-mock';

describe('users', () => {
const baseUrl = 'samples.auth0.com';
const telemetry = {name: 'react-native-auth0', version: '1.0.0'};
const telemetry = { name: 'react-native-auth0', version: '1.0.0' };
const token = 'a.token.from.the.user';
const unexpectedError = {
status: 500,
body: 'Internal Server Error....',
headers: {'Content-Type': 'text/plain'},
headers: { 'Content-Type': 'text/plain' },
};
const auth0Error = {
status: 403,
@@ -18,25 +18,25 @@ describe('users', () => {
message: 'User to be acted on does not match subject in bearer token.',
statusCode: 403,
},
headers: {'Content-Type': 'application/json'},
headers: { 'Content-Type': 'application/json' },
};

const users = new Users({baseUrl, telemetry, token});
const users = new Users({ baseUrl, telemetry, token });

beforeEach(fetchMock.restore);
beforeEach(() => fetchMock.restore());

describe('constructor', () => {
it('should build with domain', () => {
const users = new Users({baseUrl, token});
const users = new Users({ baseUrl, token });
expect(users.client.bearer).toContain(token);
});

it('should fail without token', () => {
expect(() => new Users({baseUrl})).toThrowErrorMatchingSnapshot();
expect(() => new Users({ baseUrl })).toThrowErrorMatchingSnapshot();
});

it('should fail without domain', () => {
expect(() => new Users({token})).toThrowErrorMatchingSnapshot();
expect(() => new Users({ token })).toThrowErrorMatchingSnapshot();
});
});

@@ -46,83 +46,83 @@ describe('users', () => {
it('should send correct payload', async () => {
fetchMock.getOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
user,
user
);
expect.assertions(1);
await users.getUser({id: userId});
await users.getUser({ id: userId });
expect(fetchMock.lastCall()).toMatchSnapshot();
});

it('should return successful response', async () => {
fetchMock.getOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
user,
user
);
expect.assertions(1);
await expect(users.getUser({id: userId})).resolves.toMatchSnapshot();
await expect(users.getUser({ id: userId })).resolves.toMatchSnapshot();
});

it('should handle oauth error', async () => {
fetchMock.getOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
auth0Error,
auth0Error
);
expect.assertions(1);
await expect(users.getUser({id: userId})).rejects.toMatchSnapshot();
await expect(users.getUser({ id: userId })).rejects.toMatchSnapshot();
});

it('should handle unexpected error', async () => {
fetchMock.getOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
unexpectedError,
unexpectedError
);
expect.assertions(1);
await expect(users.getUser({id: userId})).rejects.toMatchSnapshot();
await expect(users.getUser({ id: userId })).rejects.toMatchSnapshot();
});
});

describe('PATCH user', () => {
const metadata = {first_name: 'Mike', lastName: 'Doe'};
const metadata = { first_name: 'Mike', lastName: 'Doe' };
it('should send correct payload', async () => {
fetchMock.patchOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
user,
user
);
expect.assertions(1);
await users.patchUser({id: userId, metadata});
await users.patchUser({ id: userId, metadata });
expect(fetchMock.lastCall()).toMatchSnapshot();
});

it('should return successful response', async () => {
fetchMock.patchOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
user,
user
);
expect.assertions(1);
await expect(
users.patchUser({id: userId, metadata}),
users.patchUser({ id: userId, metadata })
).resolves.toMatchSnapshot();
});

it('should handle oauth error', async () => {
fetchMock.patchOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
auth0Error,
auth0Error
);
expect.assertions(1);
await expect(
users.patchUser({id: userId, metadata}),
users.patchUser({ id: userId, metadata })
).rejects.toMatchSnapshot();
});

it('should handle unexpected error', async () => {
fetchMock.patchOnce(
`https://samples.auth0.com/api/v2/users/${encodeURIComponent(userId)}`,
unexpectedError,
unexpectedError
);
expect.assertions(1);
await expect(
users.patchUser({id: userId, metadata}),
users.patchUser({ id: userId, metadata })
).rejects.toMatchSnapshot();
});
});
Loading