|
1 | | -import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
| 1 | +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; |
2 | 2 |
|
3 | | -import { seeders } from '@nangohq/shared'; |
| 3 | +import { flowService, seeders } from '@nangohq/shared'; |
4 | 4 |
|
5 | 5 | import { isError, isSuccess, runServer, shouldBeProtected, shouldRequireQueryEnv } from '../../../../../utils/tests.js'; |
6 | 6 |
|
@@ -124,4 +124,68 @@ describe(`GET ${route}`, () => { |
124 | 124 | const scriptListFile = res.json.data.flows.find((value) => value.name === 'list-files'); |
125 | 125 | expect(scriptListFile).not.toBeUndefined(); |
126 | 126 | }); |
| 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 | + }); |
127 | 191 | }); |
0 commit comments