forked from netlify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor: /tests/integration/650.command.envelope.test.cjs (n…
…etlify#5919)" This reverts commit e3d2348.
- Loading branch information
Showing
5 changed files
with
398 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,375 @@ | ||
const test = require('ava') | ||
|
||
const callCli = require('./utils/call-cli.cjs') | ||
const { getCLIOptions, withMockApi } = require('./utils/mock-api.cjs') | ||
const { withSiteBuilder } = require('./utils/site-builder.cjs') | ||
const { normalize } = require('./utils/snapshots.cjs') | ||
|
||
const siteInfo = { | ||
account_slug: 'test-account', | ||
build_settings: { | ||
env: {}, | ||
}, | ||
id: 'site_id', | ||
name: 'site-name', | ||
use_envelope: true, | ||
} | ||
const existingVar = { | ||
key: 'EXISTING_VAR', | ||
scopes: ['builds', 'functions'], | ||
values: [ | ||
{ | ||
id: '1234', | ||
context: 'production', | ||
value: 'envelope-prod-value', | ||
}, | ||
{ | ||
id: '2345', | ||
context: 'dev', | ||
value: 'envelope-dev-value', | ||
}, | ||
], | ||
} | ||
const otherVar = { | ||
key: 'OTHER_VAR', | ||
scopes: ['builds', 'functions', 'runtime', 'post_processing'], | ||
values: [ | ||
{ | ||
id: '3456', | ||
context: 'all', | ||
value: 'envelope-all-value', | ||
}, | ||
], | ||
} | ||
const envelopeResponse = [existingVar, otherVar] | ||
const routes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ path: 'sites/site_id/service-instances', response: [] }, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR', | ||
response: existingVar, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/OTHER_VAR', | ||
response: otherVar, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
response: envelopeResponse, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
method: 'POST', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR', | ||
method: 'PUT', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR', | ||
method: 'PATCH', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR/value/1234', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/OTHER_VAR', | ||
method: 'PATCH', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/OTHER_VAR', | ||
method: 'PUT', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/OTHER_VAR', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/OTHER_VAR/value/3456', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
] | ||
|
||
test('env:import should throw error if file not exists', async (t) => { | ||
await withSiteBuilder('site-env', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
await withMockApi(routes, async ({ apiUrl }) => { | ||
await t.throwsAsync(() => callCli(['env:import', '.env'], getCLIOptions({ builder, apiUrl }))) | ||
}) | ||
}) | ||
}) | ||
|
||
test('env:import --json should import new vars and override existing vars', async (t) => { | ||
await withSiteBuilder('site-env', async (builder) => { | ||
const finalEnv = { | ||
EXISTING_VAR: 'from-dotenv', | ||
OTHER_VAR: 'envelope-all-value', | ||
NEW_VAR: 'from-dotenv', | ||
} | ||
|
||
await builder | ||
.withEnvFile({ | ||
path: '.env', | ||
env: { | ||
EXISTING_VAR: 'from-dotenv', | ||
NEW_VAR: 'from-dotenv', | ||
}, | ||
}) | ||
.buildAsync() | ||
|
||
await withMockApi(routes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli(['env:import', '--json', '.env'], getCLIOptions({ builder, apiUrl }), true) | ||
|
||
t.deepEqual(cliResponse, finalEnv) | ||
}) | ||
}) | ||
}) | ||
|
||
test('env:import --json --replace-existing should replace all existing vars and return imported', async (t) => { | ||
await withSiteBuilder('site-env', async (builder) => { | ||
const finalEnv = { | ||
EXISTING_VAR: 'from-dotenv', | ||
NEW_VAR: 'from-dotenv', | ||
} | ||
|
||
await builder | ||
.withEnvFile({ | ||
path: '.env', | ||
env: { | ||
EXISTING_VAR: 'from-dotenv', | ||
NEW_VAR: 'from-dotenv', | ||
}, | ||
}) | ||
.buildAsync() | ||
|
||
await withMockApi(routes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli( | ||
['env:import', '--replace-existing', '--json', '.env'], | ||
getCLIOptions({ builder, apiUrl }), | ||
true, | ||
) | ||
|
||
t.deepEqual(cliResponse, finalEnv) | ||
}) | ||
}) | ||
}) | ||
|
||
test('env:clone should return success message (mongo to envelope)', async (t) => { | ||
const envFrom = { | ||
CLONE_ME: 'clone_me', | ||
EXISTING_VAR: 'from', | ||
} | ||
|
||
const siteInfoFrom = { | ||
...siteInfo, | ||
id: 'site_id_a', | ||
name: 'site-name-a', | ||
build_settings: { env: envFrom }, | ||
use_envelope: false, | ||
} | ||
|
||
const siteInfoTo = { | ||
...siteInfo, | ||
id: 'site_id_b', | ||
name: 'site-name-b', | ||
} | ||
|
||
const cloneRoutes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ path: 'sites/site_id_a', response: siteInfoFrom }, | ||
{ path: 'sites/site_id_b', response: siteInfoTo }, | ||
{ path: 'sites/site_id/service-instances', response: [] }, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
response: envelopeResponse, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
method: 'POST', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
] | ||
|
||
await withSiteBuilder('site-env', async (builder) => { | ||
await builder.buildAsync() | ||
await withMockApi(cloneRoutes, async ({ apiUrl, requests }) => { | ||
const cliResponse = await callCli( | ||
['env:clone', '--from', 'site_id_a', '--to', 'site_id_b'], | ||
getCLIOptions({ apiUrl, builder }), | ||
) | ||
|
||
t.snapshot(normalize(cliResponse)) | ||
|
||
const deleteRequest = requests.find((request) => request.method === 'DELETE') | ||
t.is(deleteRequest.path, '/api/v1/accounts/test-account/env/EXISTING_VAR') | ||
|
||
const postRequest = requests.find( | ||
(request) => request.method === 'POST' && request.path === '/api/v1/accounts/test-account/env', | ||
) | ||
|
||
t.is(postRequest.body.length, 2) | ||
t.is(postRequest.body[0].key, 'CLONE_ME') | ||
t.is(postRequest.body[0].values[0].value, 'clone_me') | ||
t.is(postRequest.body[1].key, 'EXISTING_VAR') | ||
t.is(postRequest.body[1].values[0].value, 'from') | ||
}) | ||
}) | ||
}) | ||
|
||
test('env:clone should return success message (envelope to mongo)', async (t) => { | ||
const siteInfoFrom = { | ||
...siteInfo, | ||
id: 'site_id_a', | ||
name: 'site-name-a', | ||
} | ||
|
||
const envTo = { | ||
CLONE_ME: 'clone_me', | ||
EXISTING_VAR: 'to', | ||
} | ||
|
||
const siteInfoTo = { | ||
...siteInfo, | ||
id: 'site_id_b', | ||
name: 'site-name-b', | ||
build_settings: { env: envTo }, | ||
use_envelope: false, | ||
} | ||
|
||
const finalEnv = { | ||
...envTo, | ||
EXISTING_VAR: 'envelope-dev-value', | ||
OTHER_VAR: 'envelope-all-value', | ||
} | ||
|
||
const cloneRoutes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ path: 'sites/site_id_a', response: siteInfoFrom }, | ||
{ path: 'sites/site_id_b', response: siteInfoTo }, | ||
{ path: 'sites/site_id/service-instances', response: [] }, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
response: envelopeResponse, | ||
}, | ||
{ | ||
path: 'sites/site_id_b', | ||
method: 'PATCH', | ||
response: {}, | ||
}, | ||
] | ||
|
||
await withSiteBuilder('site-env', async (builder) => { | ||
await builder.buildAsync() | ||
await withMockApi(cloneRoutes, async ({ apiUrl, requests }) => { | ||
const cliResponse = await callCli( | ||
['env:clone', '--from', 'site_id_a', '--to', 'site_id_b'], | ||
getCLIOptions({ apiUrl, builder }), | ||
) | ||
|
||
t.snapshot(normalize(cliResponse)) | ||
|
||
const patchRequest = requests.find( | ||
(request) => request.method === 'PATCH' && request.path === '/api/v1/sites/site_id_b', | ||
) | ||
|
||
t.deepEqual(patchRequest.body, { build_settings: { env: finalEnv } }) | ||
}) | ||
}) | ||
}) | ||
|
||
test('env:clone should return success message (envelope to envelope)', async (t) => { | ||
const siteInfoFrom = { | ||
...siteInfo, | ||
id: 'site_id_a', | ||
name: 'site-name-a', | ||
} | ||
|
||
const siteInfoTo = { | ||
...siteInfo, | ||
id: 'site_id_b', | ||
name: 'site-name-b', | ||
} | ||
|
||
const cloneRoutes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ path: 'sites/site_id_a', response: siteInfoFrom }, | ||
{ path: 'sites/site_id_b', response: siteInfoTo }, | ||
{ path: 'sites/site_id/service-instances', response: [] }, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
response: envelopeResponse, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env', | ||
method: 'POST', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/EXISTING_VAR', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
{ | ||
path: 'accounts/test-account/env/OTHER_VAR', | ||
method: 'DELETE', | ||
response: {}, | ||
}, | ||
] | ||
|
||
await withSiteBuilder('site-env', async (builder) => { | ||
await builder.buildAsync() | ||
await withMockApi(cloneRoutes, async ({ apiUrl, requests }) => { | ||
const cliResponse = await callCli( | ||
['env:clone', '--from', 'site_id_a', '--to', 'site_id_b'], | ||
getCLIOptions({ apiUrl, builder }), | ||
) | ||
|
||
t.snapshot(normalize(cliResponse)) | ||
|
||
const deleteRequests = requests.filter((request) => request.method === 'DELETE') | ||
t.is(deleteRequests.length, 2) | ||
|
||
const postRequest = requests.find((request) => request.method === 'POST') | ||
t.deepEqual( | ||
postRequest.body.map(({ key }) => key), | ||
['EXISTING_VAR', 'OTHER_VAR'], | ||
) | ||
}) | ||
}) | ||
}) |
7 changes: 0 additions & 7 deletions
7
tests/integration/commands/envelope/__snapshots__/envelope.test.mjs.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.