Skip to content

Commit

Permalink
test: rename some fixtures for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Nov 5, 2023
1 parent 5ff6e28 commit f13382d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/paste-account.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { http } from 'msw';
import { server } from '../mocks/server.js';
import { EXAMPLE_PASTE } from '../../test/fixtures.js';
import { PASTE } from '../../test/fixtures.js';
import { NOT_FOUND } from '../api/haveibeenpwned/responses.js';
import { pasteAccount } from '../paste-account.js';

describe('pasteAccount', () => {
const PASTE_ACCOUNT_DATA = [EXAMPLE_PASTE];
const PASTE_ACCOUNT_DATA = [PASTE];

describe('pasted email', () => {
it('resolves with data from the remote API', () => {
Expand Down
38 changes: 19 additions & 19 deletions src/__tests__/pwned-password-range.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { http } from 'msw';
import { server } from '../mocks/server.js';
import {
EXAMPLE_NTLM_RESPONSE_BODY,
EXAMPLE_NTLM_SUFFIXES_OBJECT,
EXAMPLE_SHA1_PREFIX,
EXAMPLE_SHA1_RESPONSE_BODY,
EXAMPLE_SHA1_SUFFIXES_OBJECT,
NTLM_RESPONSE_BODY,
NTLM_SUFFIXES_OBJECT,
SHA1_PREFIX,
SHA1_RESPONSE_BODY,
SHA1_SUFFIXES_OBJECT,
} from '../../test/fixtures.js';
import { pwnedPasswordRange } from '../pwned-password-range.js';

Expand All @@ -14,12 +14,12 @@ describe('pwnedPasswordRange', () => {
it('resolves with an object', () => {
server.use(
http.get('*', () => {
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return expect(pwnedPasswordRange(EXAMPLE_SHA1_PREFIX)).resolves.toEqual(
EXAMPLE_SHA1_SUFFIXES_OBJECT,
return expect(pwnedPasswordRange(SHA1_PREFIX)).resolves.toEqual(
SHA1_SUFFIXES_OBJECT,
);
});
});
Expand All @@ -29,13 +29,13 @@ describe('pwnedPasswordRange', () => {
const baseUrl = 'https://my-hibp-proxy:8080';
server.use(
http.get(new RegExp(`^${baseUrl}`), () => {
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return expect(
pwnedPasswordRange(EXAMPLE_SHA1_PREFIX, { baseUrl }),
).resolves.toEqual(EXAMPLE_SHA1_SUFFIXES_OBJECT);
pwnedPasswordRange(SHA1_PREFIX, { baseUrl }),
).resolves.toEqual(SHA1_SUFFIXES_OBJECT);
});
});

Expand All @@ -46,13 +46,13 @@ describe('pwnedPasswordRange', () => {
server.use(
http.get('*', ({ request }) => {
expect(request.headers.get('User-Agent')).toBe(userAgent);
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return expect(
pwnedPasswordRange(EXAMPLE_SHA1_PREFIX, { userAgent }),
).resolves.toEqual(EXAMPLE_SHA1_SUFFIXES_OBJECT);
pwnedPasswordRange(SHA1_PREFIX, { userAgent }),
).resolves.toEqual(SHA1_SUFFIXES_OBJECT);
});
});

Expand All @@ -62,11 +62,11 @@ describe('pwnedPasswordRange', () => {
server.use(
http.get('*', ({ request }) => {
expect(request.headers.get('Add-Padding')).toBe('true');
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

await pwnedPasswordRange(EXAMPLE_SHA1_PREFIX, { addPadding: true });
await pwnedPasswordRange(SHA1_PREFIX, { addPadding: true });
});
});

Expand All @@ -77,13 +77,13 @@ describe('pwnedPasswordRange', () => {
http.get('*', ({ request }) => {
const { searchParams } = new URL(request.url);
expect(searchParams.get('mode')).toBe('ntlm');
return new Response(EXAMPLE_NTLM_RESPONSE_BODY);
return new Response(NTLM_RESPONSE_BODY);
}),
);

return expect(
pwnedPasswordRange(EXAMPLE_SHA1_PREFIX, { mode: 'ntlm' }),
).resolves.toEqual(EXAMPLE_NTLM_SUFFIXES_OBJECT);
pwnedPasswordRange(SHA1_PREFIX, { mode: 'ntlm' }),
).resolves.toEqual(NTLM_SUFFIXES_OBJECT);
});
});
});
25 changes: 10 additions & 15 deletions src/__tests__/pwned-password.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import { http } from 'msw';
import { server } from '../mocks/server.js';
import {
EXAMPLE_PASSWORD,
EXAMPLE_SHA1_RESPONSE_BODY,
} from '../../test/fixtures.js';
import { PASSWORD, SHA1_RESPONSE_BODY } from '../../test/fixtures.js';
import { pwnedPassword } from '../pwned-password.js';

describe('pwnedPassword', () => {
describe('pwned', () => {
it('resolves to number > 0', () => {
server.use(
http.get('*', () => {
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return expect(pwnedPassword(EXAMPLE_PASSWORD)).resolves.toBeGreaterThan(
0,
);
return expect(pwnedPassword(PASSWORD)).resolves.toBeGreaterThan(0);
});
});

describe('clean', () => {
it('resolves to 0', () => {
server.use(
http.get('*', () => {
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

Expand All @@ -38,12 +33,12 @@ describe('pwnedPassword', () => {
const baseUrl = 'https://my-hibp-proxy:8080';
server.use(
http.get(new RegExp(`^${baseUrl}`), () => {
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return expect(
pwnedPassword(EXAMPLE_PASSWORD, { baseUrl }),
pwnedPassword(PASSWORD, { baseUrl }),
).resolves.toBeGreaterThanOrEqual(0);
});
});
Expand All @@ -55,11 +50,11 @@ describe('pwnedPassword', () => {
server.use(
http.get('*', ({ request }) => {
expect(request.headers.get('User-Agent')).toBe(userAgent);
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return pwnedPassword(EXAMPLE_PASSWORD, { userAgent });
return pwnedPassword(PASSWORD, { userAgent });
});
});

Expand All @@ -69,11 +64,11 @@ describe('pwnedPassword', () => {
server.use(
http.get('*', ({ request }) => {
expect(request.headers.get('Add-Padding')).toBe('true');
return new Response(EXAMPLE_SHA1_RESPONSE_BODY);
return new Response(SHA1_RESPONSE_BODY);
}),
);

return pwnedPassword(EXAMPLE_PASSWORD, { addPadding: true });
return pwnedPassword(PASSWORD, { addPadding: true });
});
});
});
4 changes: 2 additions & 2 deletions src/__tests__/search.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { http } from 'msw';
import { server } from '../mocks/server.js';
import { VERIFIED_BREACH, EXAMPLE_PASTE } from '../../test/fixtures.js';
import { VERIFIED_BREACH, PASTE } from '../../test/fixtures.js';
import { search } from '../search.js';

describe('search', () => {
const BREACHES = [{ Name: VERIFIED_BREACH.Name }];
const BREACHES_EXPANDED = [VERIFIED_BREACH];
const PASTES = [EXAMPLE_PASTE];
const PASTES = [PASTE];

it('searches breaches by username', () => {
server.use(
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/subscription-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { http } from 'msw';
import { server } from '../mocks/server.js';
import { EXAMPLE_SUBSCRIPTION_STATUS } from '../../test/fixtures.js';
import { SUBSCRIPTION_STATUS } from '../../test/fixtures.js';
import { subscriptionStatus } from '../subscription-status.js';

describe('subscriptionStatus', () => {
Expand All @@ -12,7 +12,7 @@ describe('subscriptionStatus', () => {
server.use(
http.get('*', ({ request }) => {
expect(request.headers.get('hibp-api-key')).toBe(apiKey);
return new Response(JSON.stringify(EXAMPLE_SUBSCRIPTION_STATUS));
return new Response(JSON.stringify(SUBSCRIPTION_STATUS));
}),
);

Expand All @@ -25,12 +25,12 @@ describe('subscriptionStatus', () => {
const baseUrl = 'https://my-hibp-proxy:8080';
server.use(
http.get(new RegExp(`^${baseUrl}`), () => {
return new Response(JSON.stringify(EXAMPLE_SUBSCRIPTION_STATUS));
return new Response(JSON.stringify(SUBSCRIPTION_STATUS));
}),
);

return expect(subscriptionStatus(apiKey, { baseUrl })).resolves.toEqual(
EXAMPLE_SUBSCRIPTION_STATUS,
SUBSCRIPTION_STATUS,
);
});
});
Expand All @@ -42,7 +42,7 @@ describe('subscriptionStatus', () => {
server.use(
http.get('*', ({ request }) => {
expect(request.headers.get('User-Agent')).toBe(userAgent);
return new Response(JSON.stringify(EXAMPLE_SUBSCRIPTION_STATUS));
return new Response(JSON.stringify(SUBSCRIPTION_STATUS));
}),
);

Expand Down
16 changes: 8 additions & 8 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export const UNVERIFIED_BREACH: Breach = {
LogoPath: 'https://haveibeenpwned.com/Content/Images/PwnedLogos/Badoo.png',
};

export const EXAMPLE_PASTE: Paste = {
export const PASTE: Paste = {
Source: 'Pastebin',
Id: '8Q0BvKD8',
Title: 'syslog',
Date: '2014-03-04T19:14:54Z',
EmailCount: 139,
};

export const EXAMPLE_SUBSCRIPTION_STATUS: SubscriptionStatus = {
export const SUBSCRIPTION_STATUS: SubscriptionStatus = {
SubscriptionName: 'Pwned 1',
Description:
'Domains with up to 25 breached addresses each, and a rate limited API key allowing 10 email address searches per minute',
Expand All @@ -71,29 +71,29 @@ export const EXAMPLE_SUBSCRIPTION_STATUS: SubscriptionStatus = {
DomainSearchMaxBreachedAccounts: 25,
};

export const EXAMPLE_PASSWORD = 'password';
export const PASSWORD = 'password';

export const EXAMPLE_SHA1_PREFIX = '5BAA6';
export const SHA1_PREFIX = '5BAA6';

export const EXAMPLE_SHA1_RESPONSE_BODY = stripIndents`
export const SHA1_RESPONSE_BODY = stripIndents`
003D68EB55068C33ACE09247EE4C639306B:3
1E4C9B93F3F0682250B6CF8331B7EE68FD8:3303003
01330C689E5D64F660D6947A93AD634EF8F:1
`;

export const EXAMPLE_SHA1_SUFFIXES_OBJECT = {
export const SHA1_SUFFIXES_OBJECT = {
'003D68EB55068C33ACE09247EE4C639306B': 3,
'1E4C9B93F3F0682250B6CF8331B7EE68FD8': 3303003,
'01330C689E5D64F660D6947A93AD634EF8F': 1,
};

export const EXAMPLE_NTLM_RESPONSE_BODY = stripIndents`
export const NTLM_RESPONSE_BODY = stripIndents`
B95AF67BEE5270A681E5410D611: 1
B964C3513680B4C0204A157CCF5: 1110
B9697A53922A10401EAB7504866: 1
`;

export const EXAMPLE_NTLM_SUFFIXES_OBJECT = {
export const NTLM_SUFFIXES_OBJECT = {
B95AF67BEE5270A681E5410D611: 1,
B964C3513680B4C0204A157CCF5: 1110,
B9697A53922A10401EAB7504866: 1,
Expand Down

0 comments on commit f13382d

Please sign in to comment.