Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deploy): reconcile flag was turned off #2419

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/lib/services/deploy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof runServer>>;

Expand Down Expand Up @@ -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<typeof res.json>([{ models: ['Output'], name: 'test', providerConfigKey: 'unauthenticated', type: 'sync' }]);
expect(res.res.status).toBe(200);
isSuccess(res.json);

expect(res.json).toStrictEqual<typeof res.json>([{ 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<typeof res.json>([]);
expect(res.res.status).toBe(200);

// Check that everything was inserted in DB
const syncConfigs = await getSyncConfigsAsStandardConfig(env!.id);
expect(syncConfigs).toBeNull();
});
});
});
Loading