Files
calendar/packages/features/flags/operations/check-if-user-has-feature.controller.test.ts
T
Eunjae LeeGitHubeunjae@cal.com <hey@eunjae.dev>eunjae@cal.com <hey@eunjae.dev>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
cef8610925 feat: add enabled column to UserFeatures and TeamFeatures for tri-state semantics (#25765)
* feat: add enabled column to UserFeatures and TeamFeatures for tri-state semantics

- Add enabled Boolean column to UserFeatures model with default true
- Add enabled Boolean column to TeamFeatures model with default true
- Update FeaturesRepository to use tri-state semantics:
  - enabled=true: feature is explicitly enabled
  - enabled=false: feature is explicitly disabled (blocks inheritance)
  - No row: inherit from team/org level
- Update SQL queries to check enabled=true for feature access
- Add enableFeatureForTeam method to interface and implementation

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* update comments

* add integration tests

* add more test

* select enabled only

* no @default(true)

* fix types and tests

* add missing enabled

* add missing enabled

* rename enableFeatureForTeam to updateFeatureForTeam and support FeatureState

* refactor: rename updateFeatureForTeam to setTeamFeatureState

Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>

* fix integration test

* fix tests

* add more tests

* add missing enabled

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-12-18 07:16:20 -03:00

25 lines
807 B
TypeScript

import prismock from "../../../../tests/libs/__mocks__/prisma";
import { expect, it } from "vitest";
import { checkIfUserHasFeatureController } from "./check-if-user-has-feature.controller";
/**
* Since our current controller doesn't run any authentication checks or input validation,
* this test is identical to the test in the use case.
*/
it("checks if user has access to feature", async () => {
const userId = 1;
await prismock.userFeatures.create({
data: {
userId,
featureId: "mock-feature",
assignedBy: "1",
updatedAt: new Date(),
enabled: true,
},
});
await expect(checkIfUserHasFeatureController(userId, "nonexistent-feature")).resolves.toBe(false);
await expect(checkIfUserHasFeatureController(userId, "mock-feature")).resolves.toBe(true);
});