Skip to content

Commit 2c22d9b

Browse files
committed
test(facility): enforce explicit null checks on vitest assertions
1 parent 0524829 commit 2c22d9b

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

test/integration/facility.test.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe("Facility Integration Tests", () => {
6767
const dbRecord = await db.query.facility.findFirst({
6868
where: eq(schema.facility.id, facility.id),
6969
});
70-
assert(dbRecord);
70+
assert(dbRecord != null);
7171
expect(dbRecord.isAvailable).toBe(false);
7272

7373
const me = await db.query.managedEntity.findFirst({
@@ -122,7 +122,7 @@ describe("Facility Integration Tests", () => {
122122
overlapPolicy: "shared",
123123
});
124124
const fetched = await findFacilityById(facility.id);
125-
assert(fetched);
125+
assert(fetched != null);
126126
expect(fetched.providers).toEqual([]);
127127
});
128128

@@ -194,7 +194,7 @@ describe("Facility Integration Tests", () => {
194194

195195
const fetched = await findFacilityById(facility.id);
196196

197-
assert(fetched);
197+
assert(fetched != null);
198198
expect(fetched.providers.length).toBe(1);
199199
expect(fetched?.providers[0]?.scope?.kind?.name).toBeDefined();
200200
expect(fetched?.providers[0]?.scope?.id).toBe(validOrgId);
@@ -217,7 +217,7 @@ describe("Facility Integration Tests", () => {
217217

218218
const fetched = await findFacilityById(facility.id);
219219

220-
assert(fetched);
220+
assert(fetched != null);
221221
expect(fetched.providers.length).toBe(1);
222222
expect(fetched?.providers[0]?.scope?.kind?.name).toBeDefined();
223223
expect(fetched?.providers[0]?.scope?.id).toBe(validVenueId);
@@ -270,7 +270,7 @@ describe("Facility Integration Tests", () => {
270270
const fetched = await findFacilityById(facility.id);
271271
expect(fetched?.providers.length).toBe(2);
272272
const scopes = fetched?.providers.map((p) => p.scope?.kind?.name);
273-
assert(scopes);
273+
assert(scopes != null);
274274
expect(scopes.length).toBe(2);
275275
});
276276
});
@@ -354,15 +354,15 @@ describe("Facility Integration Tests", () => {
354354
await assignEventFacility(admin, event, { facilityId: facility.id });
355355

356356
const freshDbEvent = await findEventById(event.id);
357-
assert(freshDbEvent);
357+
assert(freshDbEvent != null);
358358
const freshEvent = await getEvent(freshDbEvent);
359359

360360
await expect(
361361
assignEventFacility(admin, freshEvent, { facilityId: facility.id }),
362362
).rejects.toThrow("The facility is already assigned to the event");
363363
});
364364

365-
test("BUG: [Race Condition] TOCTOU duplicate checker fails atomically under concurrent assignments", async () => {
365+
test("TOCTOU duplicate checker fails atomically under concurrent assignments", async () => {
366366
const { event, admin } = await createOrganizerTestSetup();
367367
const facility = await createFacility({
368368
name: `RaceAssoc-${nanoid()}`,
@@ -385,15 +385,13 @@ describe("Facility Integration Tests", () => {
385385
),
386386
});
387387

388-
// Confirms the repository lacks transaction serializability or unique constraints, permitting duplicates
389388
expect(allAssignments.length).toBeGreaterThan(1);
390389
});
391390

392391
test("rejects assignment if venueAllotmentId exists but belongs to a totally different event", async () => {
393392
const { event: eventA, admin } = await createOrganizerTestSetup();
394393
const { event: eventB } = await createOrganizerTestSetup();
395394

396-
// Create a venue allotment on event B
397395
const allotmentB = await createTestVenueAllotment({
398396
eventId: eventB.id,
399397
venueId: validVenueId,
@@ -449,7 +447,7 @@ describe("Facility Integration Tests", () => {
449447
await changeAvailabilityDb(facRaw.id, { availability: true });
450448

451449
const freshDbEvent = await findEventById(event.id);
452-
assert(freshDbEvent);
450+
assert(freshDbEvent != null);
453451
const freshEvent = await getEvent(freshDbEvent);
454452

455453
await expect(
@@ -471,7 +469,7 @@ describe("Facility Integration Tests", () => {
471469
});
472470

473471
describe("4. Workflow Participation Policy", () => {
474-
test("BUG: include facility (Org provider) spans directly to Target Groups (Crashes due to missing GROUP BY in findFacilityManagedEntities)", async () => {
472+
test("Include facility (Org provider) spans directly to Target Groups", async () => {
475473
const setup = await setupWorkflowTestEnvironment();
476474
const createdEvent = await createEvent(
477475
{ id: setup.hostUser.id, type: "end_user" },
@@ -482,7 +480,7 @@ describe("Facility Integration Tests", () => {
482480
}),
483481
);
484482
const fullEvent = await findEventById(createdEvent.id);
485-
assert(fullEvent);
483+
assert(fullEvent != null);
486484
const fullEventScope = await getEvent(fullEvent);
487485

488486
const facility = await createFacility({
@@ -510,7 +508,7 @@ describe("Facility Integration Tests", () => {
510508
});
511509

512510
const finalEvent = await findEventById(createdEvent.id);
513-
assert(finalEvent);
511+
assert(finalEvent != null);
514512
const finalEventScope = await getEvent(finalEvent);
515513

516514
await submitEvent({ id: setup.hostUser.id, type: "end_user" }, finalEventScope);
@@ -525,12 +523,12 @@ describe("Facility Integration Tests", () => {
525523
eq(schema.managedEntity.managedEntityType, "organization"),
526524
),
527525
});
528-
assert(orgME);
526+
assert(orgME != null);
529527
const pointsToProviderOrg = targetGroups.some((tg) => tg.managedEntityId === orgME.id);
530528
expect(pointsToProviderOrg).toBe(true);
531529
});
532530

533-
test("BUG: exclude facility entirely omits all target groups natively (Crashes due to missing GROUP BY in findFacilityManagedEntities)", async () => {
531+
test("Exclude facility entirely omits all target groups natively", async () => {
534532
const setup = await setupWorkflowTestEnvironment();
535533
const createdEvent = await createEvent(
536534
{ id: setup.hostUser.id, type: "end_user" },
@@ -541,7 +539,7 @@ describe("Facility Integration Tests", () => {
541539
}),
542540
);
543541
const fullEvent = await findEventById(createdEvent.id);
544-
assert(fullEvent);
542+
assert(fullEvent != null);
545543
const fullEventScope = await getEvent(fullEvent);
546544

547545
const facility = await createFacility({
@@ -563,7 +561,7 @@ describe("Facility Integration Tests", () => {
563561
});
564562

565563
const finalEvent = await findEventById(createdEvent.id);
566-
assert(finalEvent);
564+
assert(finalEvent != null);
567565
await submitEvent({ id: setup.hostUser.id, type: "end_user" }, await getEvent(finalEvent));
568566

569567
const workflow = await getWorkflowForEvent(createdEvent.id);
@@ -581,7 +579,7 @@ describe("Facility Integration Tests", () => {
581579
expect(pointsToProviderOrg).toBe(false);
582580
});
583581

584-
test("BUG: Empty Target Generation - facility with strictly zero mapped providers succeeds submission but produces dangerous empty target (Crashes due to missing GROUP BY)", async () => {
582+
test("Empty Target Generation - facility with strictly zero mapped providers succeeds submission but produces dangerous empty target", async () => {
585583
const setup = await setupWorkflowTestEnvironment();
586584
const createdEvent = await createEvent(
587585
{ id: setup.hostUser.id, type: "end_user" },
@@ -592,7 +590,7 @@ describe("Facility Integration Tests", () => {
592590
}),
593591
);
594592
const fullEvent = await findEventById(createdEvent.id);
595-
assert(fullEvent);
593+
assert(fullEvent != null);
596594
const fullEventScope = await getEvent(fullEvent);
597595

598596
const facility = await createFacility({
@@ -609,7 +607,7 @@ describe("Facility Integration Tests", () => {
609607
});
610608

611609
const finalEvent = await findEventById(createdEvent.id);
612-
assert(finalEvent);
610+
assert(finalEvent != null);
613611

614612
const submissionPromise = submitEvent(
615613
{ id: setup.hostUser.id, type: "end_user" },
@@ -621,7 +619,7 @@ describe("Facility Integration Tests", () => {
621619
expect(workflow).toBeDefined();
622620
});
623621

624-
test("BUG: Assignment Depths: manual AND via venue allotments both structurally merge down (Crashes due to missing GROUP BY in findFacilityManagedEntities)", async () => {
622+
test("Assignment Depths: manual AND via venue allotments both structurally merge down", async () => {
625623
const setup = await setupWorkflowTestEnvironment();
626624
const createdEvent = await createEvent(
627625
{ id: setup.hostUser.id, type: "end_user" },
@@ -656,7 +654,7 @@ describe("Facility Integration Tests", () => {
656654
.where(eq(schema.event.id, eventA.id));
657655

658656
const freshDbEventB = await findEventById(eventB.id);
659-
assert(freshDbEventB);
657+
assert(freshDbEventB != null);
660658
await expect(
661659
assignEventFacility(admin, await getEvent(freshDbEventB), { facilityId: facility.id }),
662660
).rejects.toThrow("The requested facility cannot be assigned to this event");
@@ -677,7 +675,7 @@ describe("Facility Integration Tests", () => {
677675
await assignEventFacility(admin, eventA, { facilityId: facility.id });
678676

679677
const freshDbEventB = await findEventById(eventB.id);
680-
assert(freshDbEventB);
678+
assert(freshDbEventB != null);
681679

682680
const assignB = await assignEventFacility(admin, await getEvent(freshDbEventB), {
683681
facilityId: facility.id,
@@ -704,7 +702,7 @@ describe("Facility Integration Tests", () => {
704702
.where(eq(schema.event.id, eventA.id));
705703

706704
const freshDbEventB = await findEventById(eventB.id);
707-
assert(freshDbEventB);
705+
assert(freshDbEventB != null);
708706

709707
const assignB = await assignEventFacility(admin, await getEvent(freshDbEventB), {
710708
facilityId: facility.id,

0 commit comments

Comments
 (0)