From 13b67c08ba0474900e6f6d8873a82b534ac7b384 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:08:13 +0200 Subject: [PATCH] fix(deploy): reconcile flag was turned off --- packages/cli/lib/services/deploy.service.ts | 4 +- .../deploy/postDeploy.integration.test.ts | 225 ++++++++++-------- 2 files changed, 132 insertions(+), 97 deletions(-) diff --git a/packages/cli/lib/services/deploy.service.ts b/packages/cli/lib/services/deploy.service.ts index 0d5d4ba948..c5b692b3ee 100644 --- a/packages/cli/lib/services/deploy.service.ts +++ b/packages/cli/lib/services/deploy.service.ts @@ -145,7 +145,7 @@ class DeployService { const nangoYamlBody = response.yaml; const url = process.env['NANGO_HOSTPORT'] + `/sync/deploy`; - const bodyDeploy: PostDeploy['Body'] = { ...postData, reconcile: false, debug, nangoYamlBody, singleDeployMode }; + const bodyDeploy: PostDeploy['Body'] = { ...postData, reconcile: true, debug, nangoYamlBody, singleDeployMode }; if (process.env['NANGO_DEPLOY_AUTO_CONFIRM'] !== 'true' && !autoConfirm) { const confirmationUrl = process.env['NANGO_HOSTPORT'] + `/sync/deploy/confirmation`; @@ -400,7 +400,7 @@ function loadScriptJsFile({ scriptName, providerConfigKey, fullPath }: { scriptN return content; } catch (error) { - console.error(chalk.red(`Error loading file ${filePath}`), error); + console.error(chalk.red(`Error loading file ${filePath}`), error instanceof Error ? error.message : error); return null; } } diff --git a/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts b/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts index 0cf40c0327..2add1d9d6d 100644 --- a/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts +++ b/packages/server/lib/controllers/sync/deploy/postDeploy.integration.test.ts @@ -3,6 +3,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { isError, isSuccess, runServer, shouldBeProtected } from '../../../utils/tests.js'; import { getSyncConfigsAsStandardConfig, seeders } from '@nangohq/shared'; import { envs } from '@nangohq/logs'; +import type { Environment } from '@nangohq/types'; let api: Awaited>; @@ -78,106 +79,140 @@ describe(`POST ${endpoint}`, () => { expect(res.res.status).toBe(200); }); - it('should deploy', async () => { - const { env } = await seeders.seedAccountEnvAndUser(); - await seeders.createConfigSeed(env, 'unauthenticated', 'unauthenticated'); - const res = await api.fetch(endpoint, { - method: 'POST', - token: env.secret_key, - body: { - debug: false, - jsonSchema: { - $comment: '', - $schema: 'http://json-schema.org/draft-07/schema#', - definitions: {} - }, - flowConfigs: [ - { - syncName: 'test', - fileBody: { js: 'js file', ts: 'ts file' }, - providerConfigKey: 'unauthenticated', - endpoints: [{ GET: '/path' }], - runs: 'every day', - type: 'sync', - attributes: {}, - auto_start: false, - metadata: { description: 'a' }, - sync_type: 'full', - track_deletes: false, - input: 'Input', - models: ['Output'], - model_schema: [ - { - name: 'Input', - fields: [{ name: 'id', value: 'number', tsType: true, array: false, optional: false }] - }, - { - name: 'Output', - fields: [{ name: 'id', value: 'number', tsType: true, array: false, optional: false }] - } - ] - } - ], - nangoYamlBody: ``, - postConnectionScriptsByProvider: [], - reconcile: false, - singleDeployMode: false - } - }); + describe('deploy', () => { + let env: Environment; + // This describe must be executed in order - isSuccess(res.json); + it('should deploy', async () => { + const seed = await seeders.seedAccountEnvAndUser(); + env = seed.env; + await seeders.createConfigSeed(env, 'unauthenticated', 'unauthenticated'); + const res = await api.fetch(endpoint, { + method: 'POST', + token: env.secret_key, + body: { + debug: false, + jsonSchema: { + $comment: '', + $schema: 'http://json-schema.org/draft-07/schema#', + definitions: {} + }, + flowConfigs: [ + { + syncName: 'test', + fileBody: { js: 'js file', ts: 'ts file' }, + providerConfigKey: 'unauthenticated', + endpoints: [{ GET: '/path' }], + runs: 'every day', + type: 'sync', + attributes: {}, + auto_start: false, + metadata: { description: 'a' }, + sync_type: 'full', + track_deletes: false, + input: 'Input', + models: ['Output'], + model_schema: [ + { + name: 'Input', + fields: [{ name: 'id', value: 'number', tsType: true, array: false, optional: false }] + }, + { + name: 'Output', + fields: [{ name: 'id', value: 'number', tsType: true, array: false, optional: false }] + } + ] + } + ], + nangoYamlBody: ``, + postConnectionScriptsByProvider: [], + reconcile: false, + singleDeployMode: false + } + }); - expect(res.json).toStrictEqual([{ models: ['Output'], name: 'test', providerConfigKey: 'unauthenticated', type: 'sync' }]); - expect(res.res.status).toBe(200); + isSuccess(res.json); + + expect(res.json).toStrictEqual([{ models: ['Output'], name: 'test', providerConfigKey: 'unauthenticated', type: 'sync' }]); + expect(res.res.status).toBe(200); - // Check that everything was inserted in DB - const syncConfigs = await getSyncConfigsAsStandardConfig(env.id); - expect(syncConfigs).toHaveLength(1); - expect(syncConfigs).toStrictEqual([ - { - actions: [], - postConnectionScripts: [], - provider: 'unauthenticated', - providerConfigKey: 'unauthenticated', - syncs: [ - { - id: expect.any(Number), - attributes: {}, - auto_start: false, - description: 'a', - enabled: true, - endpoints: [{ GET: '/path' }], - input: { - fields: [{ array: false, name: 'id', optional: false, tsType: true, value: 'number' }], - name: 'Input' - }, - is_public: false, - last_deployed: expect.toBeIsoDate(), - layout_mode: 'nested', - models: [ - { + // Check that everything was inserted in DB + const syncConfigs = await getSyncConfigsAsStandardConfig(env!.id); + expect(syncConfigs).toHaveLength(1); + expect(syncConfigs).toStrictEqual([ + { + actions: [], + postConnectionScripts: [], + provider: 'unauthenticated', + providerConfigKey: 'unauthenticated', + syncs: [ + { + id: expect.any(Number), + attributes: {}, + auto_start: false, + description: 'a', + enabled: true, + endpoints: [{ GET: '/path' }], + input: { fields: [{ array: false, name: 'id', optional: false, tsType: true, value: 'number' }], name: 'Input' }, - { - fields: [{ array: false, name: 'id', optional: false, tsType: true, value: 'number' }], - name: 'Output' - } - ], - returns: ['Output'], - nango_yaml_version: 'v2', - scopes: [], - pre_built: false, - runs: 'every day', - name: 'test', - sync_type: 'full', - track_deletes: false, - type: 'sync', - version: '1', - webhookSubscriptions: [] - } - ] - } - ]); + is_public: false, + last_deployed: expect.toBeIsoDate(), + layout_mode: 'nested', + models: [ + { + fields: [{ array: false, name: 'id', optional: false, tsType: true, value: 'number' }], + name: 'Input' + }, + { + fields: [{ array: false, name: 'id', optional: false, tsType: true, value: 'number' }], + name: 'Output' + } + ], + returns: ['Output'], + nango_yaml_version: 'v2', + scopes: [], + pre_built: false, + runs: 'every day', + name: 'test', + sync_type: 'full', + track_deletes: false, + type: 'sync', + version: '1', + webhookSubscriptions: [] + } + ] + } + ]); + }); + + it('should have removed syncs from DB', async () => { + const res = await api.fetch(endpoint, { + method: 'POST', + token: env.secret_key, + body: { + debug: false, + jsonSchema: { + $comment: '', + $schema: 'http://json-schema.org/draft-07/schema#', + definitions: {} + }, + flowConfigs: [], + nangoYamlBody: ``, + postConnectionScriptsByProvider: [], + reconcile: true, + singleDeployMode: false + } + }); + isSuccess(res.json); + + expect(res.json).toStrictEqual([]); + expect(res.res.status).toBe(200); + + // Check that everything was inserted in DB + const syncConfigs = await getSyncConfigsAsStandardConfig(env!.id); + expect(syncConfigs).toBeNull(); + }); }); });