Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';

import { seeders } from '@nangohq/shared';
import { flowService, seeders } from '@nangohq/shared';

import { isError, isSuccess, runServer, shouldBeProtected, shouldRequireQueryEnv } from '../../../../../utils/tests.js';

Expand Down Expand Up @@ -124,4 +124,68 @@
const scriptListFile = res.json.data.flows.find((value) => value.name === 'list-files');
expect(scriptListFile).not.toBeUndefined();
});

it('should keep renamed templates visible when an older sync with the same model name exists', async () => {
const currentFlows = flowService.getAllAvailableFlowsAsStandardConfig();
const hubspotFlows = currentFlows.find((flow) => flow.providerConfigKey === 'hubspot');
const syncUsersTemplate = hubspotFlows?.syncs.find((flow) => flow.name === 'sync-users');

expect(syncUsersTemplate).not.toBeUndefined();

Check failure on line 133 in packages/server/lib/controllers/v1/integrations/providerConfigKey/flows/getFlows.integration.test.ts

View workflow job for this annotation

GitHub Actions / tests

packages/server/lib/controllers/v1/integrations/providerConfigKey/flows/getFlows.integration.test.ts > GET /api/v1/integrations/:providerConfigKey/flows > should keep renamed templates visible when an older sync with the same model name exists

AssertionError: expected undefined not to be undefined ❯ packages/server/lib/controllers/v1/integrations/providerConfigKey/flows/getFlows.integration.test.ts:133:39

const getAllAvailableFlowsAsStandardConfigSpy = vi.spyOn(flowService, 'getAllAvailableFlowsAsStandardConfig').mockReturnValue([
...currentFlows.filter((flow) => flow.providerConfigKey !== 'hubspot'),
{
providerConfigKey: 'hubspot',
actions: [],
syncs: [syncUsersTemplate!],
['on-events']: []
}
]);

try {
const { env, secret } = await seeders.seedAccountEnvAndUser();
const config = await seeders.createConfigSeed(env, 'hubspot', 'hubspot');
const connection = await seeders.createConnectionSeed({ env, provider: 'hubspot' });

await seeders.createSyncSeeds({
connectionId: connection.id,
environment_id: env.id,
nango_config_id: config.id!,
sync_name: 'users',
type: 'sync',
models: ['User'],
endpoints: [{ group: 'Users', method: 'GET', path: '/users' }]
});

const res = await api.fetch(route, {
method: 'GET',
query: { env: 'dev' },
params: { providerConfigKey: 'hubspot' },
token: secret.secret
});

expect(res.res.status).toBe(200);
isSuccess(res.json);

const oldFlow = res.json.data.flows.find((value) => value.name === 'users');
const newTemplate = res.json.data.flows.find((value) => value.name === 'sync-users');

expect(oldFlow).toMatchObject({
name: 'users',
returns: ['User'],
type: 'sync'
});
expect(newTemplate).not.toBeUndefined();
expect(newTemplate).toMatchObject({
enabled: false,
is_public: true,
name: 'sync-users',
pre_built: true,
returns: ['User'],
type: 'sync'
});
} finally {
getAllAvailableFlowsAsStandardConfigSpy.mockRestore();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@ function containsSameEndpoint(flowA: NangoSyncConfig, flowB: NangoSyncConfig) {
}

function hasSimilarFlow(templateFlow: NangoSyncConfig, list: NangoSyncConfig[]): NangoSyncConfig | false {
const modelsName = new Set<string>(templateFlow.returns.map((model) => model));

for (const flow of list) {
if (flow.type === templateFlow.type && flow.name === templateFlow.name) {
return flow;
}
if (flow.type === 'sync' && templateFlow.type === 'sync' && flow.returns.find((model) => modelsName.has(model))) {
return flow;
}
if (containsSameEndpoint(flow, templateFlow)) {
return flow;
}
Expand Down
Loading