Skip to content

Commit 737e18b

Browse files
committed
Fix not being able to see some templates
1 parent 5098c51 commit 737e18b

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

packages/server/lib/controllers/v1/integrations/providerConfigKey/flows/getFlows.integration.test.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
22

3-
import { seeders } from '@nangohq/shared';
3+
import { flowService, seeders } from '@nangohq/shared';
44

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

@@ -124,4 +124,89 @@ describe(`GET ${route}`, () => {
124124
const scriptListFile = res.json.data.flows.find((value) => value.name === 'list-files');
125125
expect(scriptListFile).not.toBeUndefined();
126126
});
127+
128+
it('should keep renamed templates visible when an older sync with the same model name exists', async () => {
129+
const currentFlows = flowService.getAllAvailableFlowsAsStandardConfig();
130+
const previousFlowsStandard = flowService.flowsStandard;
131+
132+
flowService.flowsStandard = [
133+
...currentFlows.filter((flow) => flow.providerConfigKey !== 'hubspot'),
134+
{
135+
providerConfigKey: 'hubspot',
136+
actions: [],
137+
syncs: [
138+
{
139+
name: 'sync-users',
140+
type: 'sync',
141+
returns: ['User'],
142+
description: 'Sync provisioned users',
143+
track_deletes: false,
144+
auto_start: true,
145+
sync_type: 'full',
146+
attributes: {},
147+
scopes: [],
148+
version: '1.0.0',
149+
is_public: true,
150+
pre_built: true,
151+
endpoints: [{ group: 'Users', method: 'GET', path: '/syncs/sync-users' }],
152+
runs: 'every hour',
153+
enabled: false,
154+
last_deployed: null,
155+
webhookSubscriptions: [],
156+
json_schema: null,
157+
metadata: { description: 'Sync provisioned users', scopes: [] },
158+
sdk_version: 'test-zero',
159+
features: []
160+
}
161+
],
162+
['on-events']: []
163+
}
164+
];
165+
166+
try {
167+
const { env, secret } = await seeders.seedAccountEnvAndUser();
168+
const config = await seeders.createConfigSeed(env, 'hubspot', 'hubspot');
169+
const connection = await seeders.createConnectionSeed({ env, provider: 'hubspot' });
170+
171+
await seeders.createSyncSeeds({
172+
connectionId: connection.id,
173+
environment_id: env.id,
174+
nango_config_id: config.id!,
175+
sync_name: 'users',
176+
type: 'sync',
177+
models: ['User'],
178+
endpoints: [{ group: 'Users', method: 'GET', path: '/users' }]
179+
});
180+
181+
const res = await api.fetch(route, {
182+
method: 'GET',
183+
query: { env: 'dev' },
184+
params: { providerConfigKey: 'hubspot' },
185+
token: secret.secret
186+
});
187+
188+
expect(res.res.status).toBe(200);
189+
isSuccess(res.json);
190+
191+
const oldFlow = res.json.data.flows.find((value) => value.name === 'users');
192+
const newTemplate = res.json.data.flows.find((value) => value.name === 'sync-users');
193+
194+
expect(oldFlow).toMatchObject({
195+
name: 'users',
196+
returns: ['User'],
197+
type: 'sync'
198+
});
199+
expect(newTemplate).not.toBeUndefined();
200+
expect(newTemplate).toMatchObject({
201+
enabled: false,
202+
is_public: true,
203+
name: 'sync-users',
204+
pre_built: true,
205+
returns: ['User'],
206+
type: 'sync'
207+
});
208+
} finally {
209+
flowService.flowsStandard = previousFlowsStandard;
210+
}
211+
});
127212
});

packages/server/lib/controllers/v1/integrations/providerConfigKey/flows/getFlows.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,10 @@ function containsSameEndpoint(flowA: NangoSyncConfig, flowB: NangoSyncConfig) {
7070
}
7171

7272
function hasSimilarFlow(templateFlow: NangoSyncConfig, list: NangoSyncConfig[]): NangoSyncConfig | false {
73-
const modelsName = new Set<string>(templateFlow.returns.map((model) => model));
74-
7573
for (const flow of list) {
7674
if (flow.type === templateFlow.type && flow.name === templateFlow.name) {
7775
return flow;
7876
}
79-
if (flow.type === 'sync' && templateFlow.type === 'sync' && flow.returns.find((model) => modelsName.has(model))) {
80-
return flow;
81-
}
8277
if (containsSameEndpoint(flow, templateFlow)) {
8378
return flow;
8479
}

0 commit comments

Comments
 (0)