Skip to content

Commit fd848ae

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

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

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

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
1+
import { afterAll, beforeAll, describe, expect, it, vi } 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,68 @@ 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 hubspotFlows = currentFlows.find((flow) => flow.providerConfigKey === 'hubspot');
131+
const syncUsersTemplate = hubspotFlows?.syncs.find((flow) => flow.name === 'sync-users');
132+
133+
expect(syncUsersTemplate).not.toBeUndefined();
134+
135+
const getAllAvailableFlowsAsStandardConfigSpy = vi.spyOn(flowService, 'getAllAvailableFlowsAsStandardConfig').mockReturnValue([
136+
...currentFlows.filter((flow) => flow.providerConfigKey !== 'hubspot'),
137+
{
138+
providerConfigKey: 'hubspot',
139+
actions: [],
140+
syncs: [syncUsersTemplate!],
141+
['on-events']: []
142+
}
143+
]);
144+
145+
try {
146+
const { env, secret } = await seeders.seedAccountEnvAndUser();
147+
const config = await seeders.createConfigSeed(env, 'hubspot', 'hubspot');
148+
const connection = await seeders.createConnectionSeed({ env, provider: 'hubspot' });
149+
150+
await seeders.createSyncSeeds({
151+
connectionId: connection.id,
152+
environment_id: env.id,
153+
nango_config_id: config.id!,
154+
sync_name: 'users',
155+
type: 'sync',
156+
models: ['User'],
157+
endpoints: [{ group: 'Users', method: 'GET', path: '/users' }]
158+
});
159+
160+
const res = await api.fetch(route, {
161+
method: 'GET',
162+
query: { env: 'dev' },
163+
params: { providerConfigKey: 'hubspot' },
164+
token: secret.secret
165+
});
166+
167+
expect(res.res.status).toBe(200);
168+
isSuccess(res.json);
169+
170+
const oldFlow = res.json.data.flows.find((value) => value.name === 'users');
171+
const newTemplate = res.json.data.flows.find((value) => value.name === 'sync-users');
172+
173+
expect(oldFlow).toMatchObject({
174+
name: 'users',
175+
returns: ['User'],
176+
type: 'sync'
177+
});
178+
expect(newTemplate).not.toBeUndefined();
179+
expect(newTemplate).toMatchObject({
180+
enabled: false,
181+
is_public: true,
182+
name: 'sync-users',
183+
pre_built: true,
184+
returns: ['User'],
185+
type: 'sync'
186+
});
187+
} finally {
188+
getAllAvailableFlowsAsStandardConfigSpy.mockRestore();
189+
}
190+
});
127191
});

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)