Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Reed committed Dec 27, 2023
1 parent 7bffd22 commit 889bdd3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface AbstractLocale {
}

export const US_REMOTE_LOCALE = 'us';
export const CA_REMOTE_LOCALE = 'ca';
export const CA_REMOTE_LOCALE = 'canada';
export const OTHER_LOCALE = 'other';

export class UnknownLocale implements AbstractLocale {
Expand Down Expand Up @@ -61,7 +61,6 @@ export class AllCanadaLocale implements AbstractLocale {
}

export class Locale implements AbstractLocale {
effectiveDate?: string;
country!: string;
state!: string;
stateCode!: string;
Expand Down
48 changes: 47 additions & 1 deletion src/tests/checking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
Strength,
OTHER_LOCALE,
US_REMOTE_LOCALE,
CA_REMOTE_LOCALE,
type AbstractLocale,
UnknownLocale,
AllUSLocale
AllUSLocale,
AllCanadaLocale
} from '$lib/data';
import { describe, expect, it } from 'vitest';

Expand Down Expand Up @@ -119,6 +121,19 @@ const locales: Record<string, Locale> = [
who: {
officeSupervisorInLocale: true
}
}),
new Locale({
country: 'Canada',
state: 'British Columbia',
stateCode: 'BC',
strength: Strength.Strong,
what: {
salary: true
},
when: [{ situation: Situation.Interested }],
who: {
officeSupervisorInLocale: true
}
})
].reduce((map, locale) => {
map[locale.id] = locale;
Expand All @@ -128,6 +143,7 @@ const locales: Record<string, Locale> = [
const allLocales: Record<string, AbstractLocale> = {
[OTHER_LOCALE]: new UnknownLocale(),
[US_REMOTE_LOCALE]: new AllUSLocale(),
[CA_REMOTE_LOCALE]: new AllCanadaLocale(),
...locales
};

Expand Down Expand Up @@ -301,12 +317,42 @@ describe('matches with placeholder role location', () => {
it('does not include non-matching location', () => {
expect(matches.filter((m) => m.locale.id === 'nevada').length).toBe(0);
});
it('does not include non-matching Canada location', () => {
expect(matches.filter((m) => m.locale.id === 'canada-british-columbia').length).toBe(0);
});
it('does not include abstract location matches', () => {
expect(matches.filter((m) => m.locale.id === 'us').length).toBe(0);
expect(matches.filter((m) => m.locale.id === 'canada').length).toBe(0);
expect(matches.filter((m) => m.locale.id === 'other').length).toBe(0);
});
});

describe('handles Canadian and cross-border roles', () => {
const matches = findMatchingLaws(
{
situation: Situation.Interested,
userLocation: 'canada-british-columbia',
companyLocation: 'colorado',
officeSupervisorLocation: 'other',
employeeInLocation: true,
totalEmployees: 50,
roleLocation: ['us', 'canada', 'other']
},
locales,
allLocales
);

it('includes matching user location in Canada', () => {
expect(matches).toContainEqual({
locale: locales['canada-british-columbia'],
earliestDisclosurePoint: Situation.Interested,
minEmployeesInLocale: 0,
what: { salary: true },
isGeoMatch: true
});
});
});

describe('matches with placeholder user location', () => {
const matches = findMatchingLaws(
{
Expand Down

0 comments on commit 889bdd3

Please sign in to comment.