Files
calendar/packages/features/ee/integration-attribute-sync/services/IntegrationAttributeSyncService.test.ts
T
Joe Au-YeungGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Eunjae Lee
8dbe3848e7 feat: Create Integration Attribute Sync records (#26007)
* Add db schema

* Add `CredentialRepository.findByTeamIdAndSlugs`

* Add enabled app slugs for attribute syncing

* Create repository for `IntegrationAttributeSync`

* Create zod schemas

* Create `AttributeSyncUserRuleOutputMapper`

* Create `IntegrationAttributeSyncService`

* Create DI contianer

* Create trpc endpoints

* Create page

* Include team name in `CredentialRepository.findByTeamIdAndSlugs`

* Update schema and relations

* Update types and schemas

* Add more methods to IntegrationAttributeSyncRepository

* Add more services to `IntegrationAttributeSyncService`
- getById
- Init updateIncludeRulesAndMappings

* Refactor `getTeams.handler` to use repository

* Create `createAttributeSync` trpc endpoint

* Create `updateAttributeSync` trpc endpoint

* Add router to trpc

* Create attribute sync child components

* Pass custom actions to `FormCard`

* Create `IntegrationAttributeSyncCard`

* Pass inital props via server side

* Fix prop

* Only refetch on mutation

* Fixes

* Add form error when duplicate field and attribute combo

* Add `updateTransactionWithRUleAndMappings` logic

* Adjust zod schemas

* Service add `updateIncludeRulesAndMappings`

* Pass orgId from server to component

* Rename types

* Add deleteById method to repository

* Add name to integrationAttributeSync

* Add deleteById method to service

* Rename method

* Add deleteAttributeSync trpc endpoint

* Make the IntegrationAttributeSyncCard a dummy component

* test: add tests for IntegrationAttributeSync feature

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* Move creating a attribute sync record to the service

* Add i18n strings

* Safe select credential in find by id and team

* Fix default credentialId value in form

* Update repository return types

* Add i18n string

* Make credentialId optional for form schema

* Fix label

* Add cascade deletes

* Add verification that syncs belong to org

* Create mapper for repository output

* Type fixes

* Remove old test file

* Pass `attributeOptions` from parent to children

* Infer types from zod schema

* Type fixes

* Type fix

* Clean up

* Add i18n strings

* Remove unused file

* Address feedback

* Add migration file

* Address feedback

* Add validation for new integration values

* Remove unused router

* Move away from z.infer to z.ZodType

* Clean up comments

* Type fix

* Type fixes

* Type fix

* fix: add passthrough to syncFormDataSchema to preserve extra fields

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* fix: remove incorrect test that expected extra fields to pass through syncFormDataSchema

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* Add indexes

* Add aria label

* Address feedback - consistent validation

* Fix import paths for attribute types

* refactor: change attributeSyncRules array to singular attributeSyncRule

The database schema enforces a one-to-one relationship between
IntegrationAttributeSync and AttributeSyncRule (via @unique constraint),
and the UI only supports a single rule. This change makes the TypeScript
type match the database schema and UI behavior.

Changes:
- Update IntegrationAttributeSync interface to use attributeSyncRule: AttributeSyncRule | null
- Update mapper to return singular rule instead of wrapping in array
- Update UI component to access sync.attributeSyncRule directly
- Update IIntegrationAttributeSyncUpdateParams Omit type
- Update tests to use attributeSyncRule: null instead of attributeSyncRules: []

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* feat: implement FeatureOptInService (#25805)

* feat: implement FeatureOptInService WIP

* clean up

* feat: consolidate feature repositories and add updateFeatureForUser

- Implement updateFeatureForUser in FeaturesRepository (similar to updateFeatureForTeam)
- Move getUserFeatureState and getTeamFeatureState from PrismaFeatureOptInRepository to FeaturesRepository
- Update FeatureOptInService to use only FeaturesRepository
- Add setUserFeatureState and setTeamFeatureState methods to FeatureOptInService
- Update _router.ts to remove PrismaFeatureOptInRepository usage
- Remove PrismaFeatureOptInRepository.ts and FeatureOptInRepositoryInterface.ts
- Update features.repository.interface.ts and features.repository.mock.ts
- Add integration tests for updateFeatureForUser, getUserFeatureState, getTeamFeatureState
- Update service.integration-test.ts to use FeaturesRepository

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

* refactor: rename updateFeatureForUser to setUserFeatureState

Rename to match the convention used for setTeamFeatureState

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

* refactor: return FeatureState type from getUserFeatureState and getTeamFeatureState

* fix integration tests

* clean up logics

* update services and router

* refactor: change getUserFeatureState and getTeamFeatureState to accept featureIds array

- Renamed getUserFeatureState to getUserFeatureStates
- Renamed getTeamFeatureState to getTeamFeatureStates
- Changed parameter from featureId: string to featureIds: string[]
- Changed return type from FeatureState to Record<string, FeatureState>
- Updated FeatureOptInService to use the new batch methods
- Added tests for querying multiple features in a single call
- Optimized listFeaturesForTeam to fetch all feature states in one query

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

* feat: add getFeatureStateForTeams for batch querying multiple teams

- Added getFeatureStateForTeams method to query a single feature across multiple teams in one call
- Updated FeatureOptInService.resolveFeatureStateAcrossTeams to use the new batch method
- Replaces N+1 queries with a single database query for team states
- Added comprehensive integration tests for the new method

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

* refactor: combine org and team state queries into single call

- Include orgId in the teamIds array passed to getFeatureStateForTeams
- Extract org state and team states from the combined result
- Reduces database queries from 3 to 2 in resolveFeatureStateAcrossTeams

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

* refactor: use team.isOrganization and clarify computeEffectiveState comment

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

* refactor: use MembershipRepository.findAllByUserId with isOrganization

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

* feat: add featureId validation using isOptInFeature type guard

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

* less queries

* add fallback value

* fix type error

* move files

* add autoOptInFeatures column

* use autoOptInFeatures flag within FeatureOptInService

* add setUserAutoOptIn and setTeamAutoOptIn

* fix computeEffectiveState logic

* rewrite computeEffectiveState

* clean up integration tests

* clean up in afterEach

* fix type error

* refactor: use FeaturesRepository methods instead of direct Prisma calls

Replace all manual userFeatures and teamFeatures Prisma operations with
the new setUserFeatureState and setTeamFeatureState repository methods.

Changes include:
- Admin handlers (assignFeatureToTeam, unassignFeatureFromTeam)
- Test fixtures and integration tests
- Playwright fixtures
- Development scripts

This ensures consistent feature flag management through the repository
pattern and supports the new tri-state semantics (enabled/disabled/inherit).

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

* clean up

* fix the logic

* extract some logic into applyAutoOptIn()

* remove wrong code

* refactor: convert setUserFeatureState and setTeamFeatureState to object params with discriminated union

- Convert multiple positional parameters to single object parameter
- Use discriminated union types: assignedBy required for enabled/disabled, omitted for inherit
- Update all callers across repository, service, handlers, fixtures, and tests

* fix type error

* use Promise.all

* fix

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* Prevent duplicate field and attribute mappings

* Add validation that attribute belongs to the org

* fix: address Cubic AI review feedback

- Add @@index([credentialId]) to IntegrationAttributeSync model for efficient cascade deletes and credential-based queries (confidence: 9/10)
- Fix translation key from 'credential_required' to 'attribute_sync_credential_required' to match existing locale definition (confidence: 10/10)

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* fix: address remaining cubic review feedback

- RuleBuilder.tsx: Use unique IDs for React keys instead of array index to prevent reconciliation bugs when removing conditions
- updateAttributeSync.handler.ts: Add early organization check before service calls for consistency
- createAttributeSync.handler.ts: Add CredentialNotFoundError class for type-safe error handling instead of string matching
- IntegrationAttributeSyncService.test.ts: Replace expect.fail() with proper Vitest rejects.toSatisfy() pattern

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>

* Pull test file from main

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Eunjae Lee <hey@eunjae.dev>
2026-01-12 22:57:28 +00:00

445 lines
17 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import type { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
import { enabledAppSlugs } from "../constants";
import type { IIntegrationAttributeSyncRepository } from "../repositories/IIntegrationAttributeSyncRepository";
import { IntegrationAttributeSyncService, UnauthorizedAttributeError } from "./IntegrationAttributeSyncService";
describe("IntegrationAttributeSyncService", () => {
let service: IntegrationAttributeSyncService;
let mockCredentialRepository: {
findByTeamIdAndSlugs: ReturnType<typeof vi.fn>;
};
let mockIntegrationAttributeSyncRepository: {
getByOrganizationId: ReturnType<typeof vi.fn>;
getById: ReturnType<typeof vi.fn>;
getSyncFieldMappings: ReturnType<typeof vi.fn>;
getMappedAttributeIdsByOrganization: ReturnType<typeof vi.fn>;
getAttributeIdsByOrganization: ReturnType<typeof vi.fn>;
updateTransactionWithRuleAndMappings: ReturnType<typeof vi.fn>;
deleteById: ReturnType<typeof vi.fn>;
};
beforeEach(() => {
vi.resetAllMocks();
mockCredentialRepository = {
findByTeamIdAndSlugs: vi.fn(),
};
mockIntegrationAttributeSyncRepository = {
getByOrganizationId: vi.fn(),
getById: vi.fn(),
getSyncFieldMappings: vi.fn(),
getMappedAttributeIdsByOrganization: vi.fn(),
getAttributeIdsByOrganization: vi.fn(),
updateTransactionWithRuleAndMappings: vi.fn(),
deleteById: vi.fn(),
};
service = new IntegrationAttributeSyncService({
credentialRepository: mockCredentialRepository as unknown as CredentialRepository,
integrationAttributeSyncRepository:
mockIntegrationAttributeSyncRepository as unknown as IIntegrationAttributeSyncRepository,
});
});
describe("getEnabledAppCredentials", () => {
it("should call credentialRepository.findByTeamIdAndSlugs with correct params", async () => {
const organizationId = 123;
const expectedCredentials = [
{ id: 1, type: "salesforce", teamId: organizationId },
{ id: 2, type: "salesforce", teamId: organizationId },
];
mockCredentialRepository.findByTeamIdAndSlugs.mockResolvedValue(expectedCredentials);
const result = await service.getEnabledAppCredentials(organizationId);
expect(mockCredentialRepository.findByTeamIdAndSlugs).toHaveBeenCalledWith({
teamId: organizationId,
slugs: enabledAppSlugs,
});
expect(result).toEqual(expectedCredentials);
});
it("should return empty array when no credentials found", async () => {
const organizationId = 123;
mockCredentialRepository.findByTeamIdAndSlugs.mockResolvedValue([]);
const result = await service.getEnabledAppCredentials(organizationId);
expect(result).toEqual([]);
});
});
describe("getAllIntegrationAttributeSyncs", () => {
it("should call repository.getByOrganizationId with correct organizationId", async () => {
const organizationId = 456;
const expectedSyncs = [
{
id: "sync-1",
name: "Sync 1",
organizationId,
integration: "salesforce",
enabled: true,
attributeSyncRule: null,
syncFieldMappings: [],
},
];
mockIntegrationAttributeSyncRepository.getByOrganizationId.mockResolvedValue(expectedSyncs);
const result = await service.getAllIntegrationAttributeSyncs(organizationId);
expect(mockIntegrationAttributeSyncRepository.getByOrganizationId).toHaveBeenCalledWith(organizationId);
expect(result).toEqual(expectedSyncs);
});
it("should return empty array when no syncs found", async () => {
const organizationId = 456;
mockIntegrationAttributeSyncRepository.getByOrganizationId.mockResolvedValue([]);
const result = await service.getAllIntegrationAttributeSyncs(organizationId);
expect(result).toEqual([]);
});
});
describe("getById", () => {
it("should call repository.getById with correct id", async () => {
const syncId = "sync-123";
const expectedSync = {
id: syncId,
name: "Test Sync",
organizationId: 123,
integration: "salesforce",
enabled: true,
attributeSyncRule: null,
syncFieldMappings: [],
};
mockIntegrationAttributeSyncRepository.getById.mockResolvedValue(expectedSync);
const result = await service.getById(syncId);
expect(mockIntegrationAttributeSyncRepository.getById).toHaveBeenCalledWith(syncId);
expect(result).toEqual(expectedSync);
});
it("should return null when sync not found", async () => {
const syncId = "non-existent";
mockIntegrationAttributeSyncRepository.getById.mockResolvedValue(null);
const result = await service.getById(syncId);
expect(result).toBeNull();
});
});
describe("updateIncludeRulesAndMappings", () => {
const baseFormData = {
id: "sync-123",
name: "Test Sync",
credentialId: 1,
enabled: true,
organizationId: 123,
ruleId: "rule-123",
rule: {
operator: "AND" as const,
conditions: [
{
identifier: "teamId" as const,
operator: "equals" as const,
value: [1, 2],
},
],
},
};
it("should create new mappings when they don't have ids", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ integrationFieldName: "field2", attributeId: "attr-2", enabled: false },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-1", "attr-2"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await service.updateIncludeRulesAndMappings(formData);
expect(mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings).toHaveBeenCalledWith({
integrationAttributeSync: {
id: formData.id,
name: formData.name,
credentialId: formData.credentialId,
enabled: formData.enabled,
organizationId: formData.organizationId,
},
attributeSyncRule: {
id: formData.ruleId,
rule: formData.rule,
},
fieldMappingsToCreate: formData.syncFieldMappings,
fieldMappingsToUpdate: [],
fieldMappingsToDelete: [],
});
});
it("should update existing mappings when they have ids", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ id: "mapping-1", integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ id: "mapping-2", integrationFieldName: "field2", attributeId: "attr-2", enabled: false },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-1", "attr-2"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([
{ id: "mapping-1", integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ id: "mapping-2", integrationFieldName: "field2", attributeId: "attr-2", enabled: true },
]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await service.updateIncludeRulesAndMappings(formData);
expect(mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings).toHaveBeenCalledWith({
integrationAttributeSync: {
id: formData.id,
name: formData.name,
credentialId: formData.credentialId,
enabled: formData.enabled,
organizationId: formData.organizationId,
},
attributeSyncRule: {
id: formData.ruleId,
rule: formData.rule,
},
fieldMappingsToCreate: [],
fieldMappingsToUpdate: formData.syncFieldMappings,
fieldMappingsToDelete: [],
});
});
it("should delete mappings that are no longer in the form data", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ id: "mapping-1", integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-1"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([
{ id: "mapping-1", integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ id: "mapping-2", integrationFieldName: "field2", attributeId: "attr-2", enabled: true },
{ id: "mapping-3", integrationFieldName: "field3", attributeId: "attr-3", enabled: true },
]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await service.updateIncludeRulesAndMappings(formData);
expect(mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings).toHaveBeenCalledWith({
integrationAttributeSync: {
id: formData.id,
name: formData.name,
credentialId: formData.credentialId,
enabled: formData.enabled,
organizationId: formData.organizationId,
},
attributeSyncRule: {
id: formData.ruleId,
rule: formData.rule,
},
fieldMappingsToCreate: [],
fieldMappingsToUpdate: [formData.syncFieldMappings[0]],
fieldMappingsToDelete: ["mapping-2", "mapping-3"],
});
});
it("should handle mixed create, update, and delete operations", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ id: "mapping-1", integrationFieldName: "field1-updated", attributeId: "attr-1", enabled: false },
{ integrationFieldName: "field-new", attributeId: "attr-new", enabled: true },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-1", "attr-new"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([
{ id: "mapping-1", integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ id: "mapping-2", integrationFieldName: "field2", attributeId: "attr-2", enabled: true },
]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await service.updateIncludeRulesAndMappings(formData);
expect(mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings).toHaveBeenCalledWith({
integrationAttributeSync: {
id: formData.id,
name: formData.name,
credentialId: formData.credentialId,
enabled: formData.enabled,
organizationId: formData.organizationId,
},
attributeSyncRule: {
id: formData.ruleId,
rule: formData.rule,
},
fieldMappingsToCreate: [
{ integrationFieldName: "field-new", attributeId: "attr-new", enabled: true },
],
fieldMappingsToUpdate: [
{ id: "mapping-1", integrationFieldName: "field1-updated", attributeId: "attr-1", enabled: false },
],
fieldMappingsToDelete: ["mapping-2"],
});
});
it("should handle attribute-based conditions in rules", async () => {
const formData = {
...baseFormData,
rule: {
operator: "OR" as const,
conditions: [
{
identifier: "attributeId" as const,
attributeId: "attr-123",
operator: "in" as const,
value: ["option-1", "option-2"],
},
],
},
syncFieldMappings: [],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await service.updateIncludeRulesAndMappings(formData);
expect(mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings).toHaveBeenCalledWith(
expect.objectContaining({
attributeSyncRule: {
id: formData.ruleId,
rule: formData.rule,
},
})
);
});
});
describe("validateAttributeOwnership", () => {
const baseFormData = {
id: "sync-123",
name: "Test Sync",
credentialId: 1,
enabled: true,
organizationId: 123,
ruleId: "rule-123",
rule: {
operator: "AND" as const,
conditions: [
{
identifier: "teamId" as const,
operator: "equals" as const,
value: [1, 2],
},
],
},
};
it("should throw UnauthorizedAttributeError when attribute does not belong to organization", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ integrationFieldName: "field2", attributeId: "attr-invalid", enabled: true },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-1"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([]);
await expect(service.updateIncludeRulesAndMappings(formData)).rejects.toThrow(UnauthorizedAttributeError);
});
it("should include invalid attribute ids in the error", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ integrationFieldName: "field1", attributeId: "attr-valid", enabled: true },
{ integrationFieldName: "field2", attributeId: "attr-invalid-1", enabled: true },
{ integrationFieldName: "field3", attributeId: "attr-invalid-2", enabled: true },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-valid"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([]);
await expect(service.updateIncludeRulesAndMappings(formData)).rejects.toSatisfy((error) => {
expect(error).toBeInstanceOf(UnauthorizedAttributeError);
expect((error as UnauthorizedAttributeError).attributeIds).toEqual(["attr-invalid-1", "attr-invalid-2"]);
return true;
});
});
it("should pass validation when all attributes belong to organization", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [
{ integrationFieldName: "field1", attributeId: "attr-1", enabled: true },
{ integrationFieldName: "field2", attributeId: "attr-2", enabled: true },
],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue(["attr-1", "attr-2"]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await expect(service.updateIncludeRulesAndMappings(formData)).resolves.not.toThrow();
});
it("should pass validation when syncFieldMappings is empty", async () => {
const formData = {
...baseFormData,
syncFieldMappings: [],
};
mockIntegrationAttributeSyncRepository.getMappedAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getAttributeIdsByOrganization.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.getSyncFieldMappings.mockResolvedValue([]);
mockIntegrationAttributeSyncRepository.updateTransactionWithRuleAndMappings.mockResolvedValue(undefined);
await expect(service.updateIncludeRulesAndMappings(formData)).resolves.not.toThrow();
});
});
describe("deleteById", () => {
it("should call repository.deleteById with correct id", async () => {
const syncId = "sync-to-delete";
mockIntegrationAttributeSyncRepository.deleteById.mockResolvedValue(undefined);
await service.deleteById(syncId);
expect(mockIntegrationAttributeSyncRepository.deleteById).toHaveBeenCalledWith(syncId);
});
});
});