Skip to content
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

Remove all mentions of deprecated categories #782

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
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
80 changes: 14 additions & 66 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 @@ -96,8 +95,6 @@ describe("Firestore rules", () => {
});

describe("Slots rules", () => {
// const getSlotDocPath(organization, baseSlot.id) = [getSlotsPath(organization), baseSlot.id].join("/");

testWithEmulator("should not allow access to unauth user", async () => {
const { db, organization } = await getTestEnv({
auth: false,
Expand Down Expand Up @@ -150,6 +147,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if slot type not valid",
async () => {
Expand All @@ -162,6 +160,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if slot category not valid",
async () => {
Expand All @@ -177,43 +176,7 @@ 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 @@ -341,6 +304,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow update access to non-admins",
async () => {
Expand All @@ -367,6 +331,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow delete access to non-admins (as it's handled through cloud functions)",
async () => {
Expand Down Expand Up @@ -479,6 +444,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update of booking subscribing to non-existing interval",
async () => {
Expand All @@ -504,6 +470,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update of invalid booking entry",
async () => {
Expand Down Expand Up @@ -532,6 +499,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow customer to subscribe to slot not supporting their category",
async () => {
Expand Down Expand Up @@ -625,6 +593,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should allow create/update with empty strings as values of optional strings (as is in CustomerForm in production)",
async () => {
Expand All @@ -647,6 +616,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if 'certificateExpiration' provided, but not a valid date",
async () => {
Expand All @@ -668,6 +638,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if birthday provided, but not a valid date",
async () => {
Expand All @@ -689,6 +660,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if phone provided but not valid",
async () => {
Expand Down Expand Up @@ -752,6 +724,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if email provided but not valid",
async () => {
Expand All @@ -773,6 +746,7 @@ describe("Firestore rules", () => {
);
}
);

testWithEmulator(
"should not allow create/update if invalid category",
async () => {
Expand All @@ -786,33 +760,7 @@ 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 allow `extendedDate` update", async () => {
const { db, organization } = await getTestEnv({
setup: (db, { organization }) =>
Expand Down
Loading