Skip to content

Commit

Permalink
Remove all mentions of deprecated categories
Browse files Browse the repository at this point in the history
  • Loading branch information
ikusteu committed Jul 8, 2023
1 parent 1103e37 commit f39ca36
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 469 deletions.
65 changes: 0 additions & 65 deletions packages/client/src/__tests__/firestoreRules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
SlotType,
Customer,
sanitizeCustomer,
DeprecatedCategory,
} from "@eisbuk/shared";

import { defaultCustomerFormValues } from "@/lib/data";
Expand Down Expand Up @@ -177,43 +176,6 @@ describe("Firestore rules", () => {
);
}
);
testWithEmulator(
'should allow updating a slot with "adults" category, but disallow new creating new slots with said category',
() => {
async () => {
const slotWithAdults = {
...baseSlot,
categories: [DeprecatedCategory.Adults],
id: "slot-with-adults",
};

const { db, organization } = await getTestEnv({
setup: (db, { organization }) =>
Promise.all([
setDoc(
doc(db, getSlotDocPath(organization, "slot-with-adults")),
slotWithAdults
),
]),
});

// The deprecated category already exists in the slot, we should allow it to stay there
await assertSucceeds(
setDoc(doc(db, getSlotDocPath(organization, "slot-with-adults")), {
...baseSlot,
categories: [Category.Competitive, DeprecatedCategory.Adults],
})
);
// We're not allowing the creation of new slots with deprecated values
await assertFails(
setDoc(doc(db, getSlotDocPath(organization, "new-slot")), {
...baseSlot,
categories: [Category.Competitive, DeprecatedCategory.Adults],
})
);
};
}
);
/**
* @TODO as firestore.rules don't allow loops or iterations
* we need to apply this when we agree on maximum number of intervals per slot
Expand Down Expand Up @@ -807,33 +769,6 @@ describe("Firestore rules", () => {
);
}
);
testWithEmulator(
'should allow updating customer in "adults" category, but disallow creation of new customers in (non-spacific) "adults" category',
async () => {
const { db, organization } = await getTestEnv({
setup: (db, { organization }) =>
setDoc(doc(db, getCustomerDocPath(organization, saul.id)), {
...saul,
categories: [DeprecatedCategory.Adults],
}),
});
// Should allow updating, even though category = "adults"
await assertSucceeds(
setDoc(doc(db, getCustomerDocPath(organization, saul.id)), {
...saul,
categories: [DeprecatedCategory.Adults],
name: "Jimmy",
})
);
// Should disallow creation of new customers with category "adults"
await assertFails(
setDoc(doc(db, getCustomerDocPath(organization, "new-customer")), {
...saul,
categories: [DeprecatedCategory.Adults],
})
);
}
);
testWithEmulator(
"should not allow create/update if 'covidCertificateSuspended' provided, but not boolean",
async () => {
Expand Down
129 changes: 1 addition & 128 deletions packages/client/src/__tests__/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import { describe, expect } from "vitest";
import { httpsCallable, FunctionsError } from "@firebase/functions";

import {
HTTPSErrors,
sanitizeCustomer,
Category,
DeprecatedCategory,
} from "@eisbuk/shared";
import { HTTPSErrors, sanitizeCustomer } from "@eisbuk/shared";
import { CloudFunction } from "@eisbuk/shared/ui";

import {
Expand All @@ -21,7 +16,6 @@ import {
unprunedMonth,
} from "@eisbuk/testing/migrations";
import * as customers from "@eisbuk/testing/customers";
import { baseSlot } from "@eisbuk/testing/slots";
import { saul } from "@eisbuk/testing/customers";

import { functions, adminDb } from "@/__testSetup__/firestoreSetup";
Expand All @@ -32,7 +26,6 @@ import {
getBookingsDocPath,
getBookingsPath,
getCustomerDocPath,
getSlotDocPath,
getSlotsByDayPath,
} from "@/utils/firestore";

Expand Down Expand Up @@ -128,126 +121,6 @@ describe("Migrations", () => {
});
});

describe("'migrateSlotsCategoriesToExplicitMinors'", () => {
testWithEmulator(
'should replace "pre-competitive" and "course" category entries with corresponging "-minor" category entries, while leaving the existing categories as they are',
async () => {
const { organization } = await setUpOrganization();
const courseSlot = {
...baseSlot,
categories: [Category.Competitive, DeprecatedCategory.Course],
id: "course-slot",
};
const preCompetitiveSlot = {
...baseSlot,
categories: [Category.Competitive, DeprecatedCategory.PreCompetitive],
id: "pre-competitive-slot",
};
// Edge case, if the category already exists, shouldn't be duplicated
const courseMinorsSlot = {
...baseSlot,
categories: [Category.CourseMinors, DeprecatedCategory.Course],
id: "pre-competitive-minors-slot",
};

const courseSlotRef = adminDb.doc(
getSlotDocPath(organization, courseSlot.id)
);
const preCompetitiveSlotRef = adminDb.doc(
getSlotDocPath(organization, preCompetitiveSlot.id)
);
const courseMinorsSlotRef = adminDb.doc(
getSlotDocPath(organization, courseMinorsSlot.id)
);

await Promise.all([
courseSlotRef.set(courseSlot),
preCompetitiveSlotRef.set(preCompetitiveSlot),
courseMinorsSlotRef.set(courseMinorsSlot),
]);

await invokeFunction(CloudFunction.MigrateCategoriesToExplicitMinors)({
organization,
});

const [resCourse, resPreCompetitive, resCourseMinors] =
await Promise.all([
courseSlotRef.get(),
preCompetitiveSlotRef.get(),
courseMinorsSlotRef.get(),
]);
expect(resCourse.data()).toEqual({
...courseSlot,
categories: [Category.Competitive, Category.CourseMinors],
});
expect(resPreCompetitive.data()).toEqual({
...preCompetitiveSlot,
categories: [Category.Competitive, Category.PreCompetitiveMinors],
});
expect(resCourseMinors.data()).toEqual({
...courseMinorsSlot,
categories: [Category.CourseMinors],
});
}
);

testWithEmulator(
'should replace "pre-competitive" and "course" category entries with corresponging "-minor" category entries, in customer documents',
async () => {
const { organization } = await setUpOrganization();

const courseCustomer = {
...saul,
categories: [DeprecatedCategory.Course],
id: "course-customer",
};
const preCompetitiveCustomer = {
...saul,
categories: [DeprecatedCategory.PreCompetitive],
id: "pre-competitive-customer",
};

const courseCustomerRef = adminDb.doc(
getCustomerDocPath(organization, courseCustomer.id)
);
const preCompetitiveCustomerRef = adminDb.doc(
getCustomerDocPath(organization, preCompetitiveCustomer.id)
);

await Promise.all([
courseCustomerRef.set(courseCustomer),
preCompetitiveCustomerRef.set(preCompetitiveCustomer),
]);

await invokeFunction(CloudFunction.MigrateCategoriesToExplicitMinors)({
organization,
});

const [resCourse, resPreCompetitive] = await Promise.all([
courseCustomerRef.get(),
preCompetitiveCustomerRef.get(),
]);
expect(resCourse.data()).toEqual({
...courseCustomer,
categories: [Category.CourseMinors],
});
expect(resPreCompetitive.data()).toEqual({
...preCompetitiveCustomer,
categories: [Category.PreCompetitiveMinors],
});
}
);

testWithEmulator("should not allow calls to non-admins", async () => {
const { organization } = await setUpOrganization({ doLogin: false });
await expect(
invokeFunction(CloudFunction.MigrateCategoriesToExplicitMinors)({
organization,
})
).rejects.toThrow(HTTPSErrors.Unauth);
});
});

describe("customersToPluralCategories", () => {
testWithEmulator(
"should change customer's category field into an array instead of scalar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { DateTime } from "luxon";
import {
BookingSubCollection,
Category,
DeprecatedCategory,
sanitizeCustomer,
OrgSubCollection,
SlotsByDay,
Expand Down Expand Up @@ -44,7 +43,7 @@ const setupBookingsTest = ({
date,
slotsByDay,
}: {
category: Category | DeprecatedCategory;
category: Category;
date: DateTime;
slotsByDay: NonNullable<LocalStore["firestore"]["data"]["slotsByDay"]>;
}): ReturnType<typeof getNewStore> => {
Expand Down Expand Up @@ -80,80 +79,6 @@ describe("Selectors ->", () => {
const res = getSlotsForCustomer(store.getState());
expect(res).toEqual(expectedMonthCustomer);
});

const courseAdultsSlot = {
...baseSlot,
id: "course",
categories: [Category.CourseAdults],
};
const preCompetitiveAdultsSlot = {
...baseSlot,
id: "pre-competitive",
categories: [Category.PreCompetitiveAdults],
};
const adultsSlot = {
...baseSlot,
id: "adults",
categories: [DeprecatedCategory.Adults as unknown as Category],
};
const competitiveSlot = {
...baseSlot,
id: "competitive",
categories: [Category.Competitive],
};

test('should display both "pre-competitive-adults" and "course-adults" slots to unsorted "adults" customers', () => {
const date = DateTime.fromISO(baseSlot.date);
const currentMonthString = baseSlot.date.substring(0, 7);
const store = setupBookingsTest({
category: DeprecatedCategory.Adults,
date,
slotsByDay: {
[currentMonthString]: {
["2021-03-01"]: {
[courseAdultsSlot.id]: courseAdultsSlot,
[preCompetitiveAdultsSlot.id]: preCompetitiveAdultsSlot,
[competitiveSlot.id]: competitiveSlot,
},
},
},
});
const res = getSlotsForCustomer(store.getState());
// Should only filter the "competitive" slot
expect(res).toEqual({
["2021-03-01"]: {
[courseAdultsSlot.id]: courseAdultsSlot,
[preCompetitiveAdultsSlot.id]: preCompetitiveAdultsSlot,
},
});
});

test('should display slots with category "adults" to both "pre-competitive-adults" and "course-adults" customers', () => {
const date = DateTime.fromISO(baseSlot.date);
const currentMonthString = baseSlot.date.substring(0, 7);
const store = setupBookingsTest({
category: Category.CourseAdults,
date,
slotsByDay: {
[currentMonthString]: {
/** @TODO_TESTS hardcoded test date, make this a bit more concise */
["2021-03-01"]: {
[courseAdultsSlot.id]: courseAdultsSlot,
[preCompetitiveAdultsSlot.id]: preCompetitiveAdultsSlot,
[adultsSlot.id]: adultsSlot,
[competitiveSlot.id]: competitiveSlot,
},
},
},
});
const res = getSlotsForCustomer(store.getState());
expect(res).toEqual({
["2021-03-01"]: {
[courseAdultsSlot.id]: courseAdultsSlot,
[adultsSlot.id]: adultsSlot,
},
});
});
});

describe("Test 'getCanBook' selector", () => {
Expand Down
Loading

0 comments on commit f39ca36

Please sign in to comment.