|
1 | 1 | import { afterAll, beforeAll, describe, expect, it } 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,89 @@ 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 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 | + }); |
127 | 212 | }); |
0 commit comments