Skip to content
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"winston": "^3.15.0"
},
"devDependencies": {
"@oclif/test": "^4.0.9",
"@oclif/test": "^4.1.0",
"chai": "^4.5.0",
"eslint": "^8.57.1",
"globby": "^10.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,110 +4,112 @@ const { constants } = require('../setup');
const path = require('path');
const { migrationPath } = constants;
const nockBack = require('nock').back;
const { expect, test } = require('@oclif/test');
const { runCommand } = require('@oclif/test');
const { expect } = require('chai');
const { fancy } = require('fancy-test');

describe('Create content type from migration script', () => {
nockBack.fixtures = path.join(__dirname, '__nock-fixtures__');
nockBack.setMode('record');
describe('Create content type with passing options as arguments', () => {
nockBack('create-content-type.json', (nockDone) => {
test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
'cm:migration',
'-n',
`${migrationPath}/create-ct/create-ct-opts.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should create content type', (ctx) => {
expect(ctx.stdout).to.contain('Successfully added content type: foo3');
nockDone();
});
fancy.it('Should create content type', async () => {
const { stdout } = await runCommand(
[
'cm:migration',
'-n',
`${migrationPath}/create-ct/create-ct-opts.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],
{ root: process.cwd() },
);
expect(stdout).to.contain('Successfully added content type: foo3');
nockDone();
});

test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
fancy.it('Should update content type', async () => {
const { stdout } = await runCommand(
[
'cm:migration',
'-n',
`${migrationPath}/edit-ct/edit-ct.success.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],
{ root: process.cwd() },
);
expect(stdout).to.contain('Successfully updated content type: foo3\n');
nockDone();
});

fancy.it('Should delete content type', async () => {
const { stdout } = await runCommand(
[
'cm:migration',
'-n',
`${migrationPath}/edit-ct/delete-ct.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],
{ root: process.cwd() },
);
expect(stdout).to.contain('Successfully executed task: Deleting content type\n');
nockDone();
});
});
});

describe('should show error for misspelled properties', () => {
fancy.it('Should show error message for invalid prop set', async () => {
const { stdout } = await runCommand(
[
'cm:migration',
'-n',
`${migrationPath}/edit-ct/edit-ct.success.js`,
`${migrationPath}/create-ct/create-ct-misspelled-props.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should update content type', (ctx) => {
expect(ctx.stdout).to.contain('Successfully updated content type: foo3\n');
nockDone();
});
],
{ root: process.cwd() },
);
expect(stdout).to.contains('description is missing.');
});

test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
fancy.it('Should show error message for invalid function call', async () => {
const { stdout } = await runCommand(
[
'cm:migration',
'-n',
`${migrationPath}/edit-ct/delete-ct.js`,
`${migrationPath}/create-ct/create-ct-misspelled.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should delete content type', (ctx) => {
expect(ctx.stdout).to.contain('Successfully executed task: Deleting content type\n');
nockDone();
});
],
{ root: process.cwd() },
);
expect(stdout).to.contains('data_tyep is not a valid function');
});
});

describe('should show error for misspelled properties', () => {
test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
'cm:migration',
'-n',
`${migrationPath}/create-ct/create-ct-misspelled-props.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should show error message for invalid prop set', async (ctx) => {
expect(ctx.stdout).to.contains('description is missing.');
});

test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
'cm:migration',
'-n',
`${migrationPath}/create-ct/create-ct-misspelled.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should show error message for invalid function call', async (ctx) => {
expect(ctx.stdout).to.contains('data_tyep is not a valid function');
});

nockBack('missing-required-field.json', (nockDone) => {
test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
'cm:migration',
'-n',
`${migrationPath}/edit-field/missing-required-fields.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should show error message for invalid function call', async (ctx) => {
expect(ctx.stdout).to.contains("should have a 'title' field.\"");
nockDone();
});
fancy.it('Should show error message for invalid function call', async () => {
const { stdout } = await runCommand(
[
'cm:migration',
'-n',
`${migrationPath}/edit-field/missing-required-fields.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],
{ root: process.cwd() },
);
expect(stdout).to.contains("should have a 'title' field.\"");
nockDone();
});
});
});
});
94 changes: 46 additions & 48 deletions packages/contentstack-migration/test/commands/delete-field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,72 @@ const { constants } = require('../setup');
const { migrationPath } = constants;
const path = require('path');
const nockBack = require('nock').back;
const { expect, test } = require('@oclif/test');
const { runCommand } = require('@oclif/test');
const { expect } = require('chai');
const { fancy } = require('fancy-test');
const env = { ...process.env };

describe('Delete field test from migration script', () => {
nockBack.fixtures = path.join(__dirname, '__nock-fixtures__');
nockBack.setMode('record');

describe('prepare for field test', () => {
test
.loadConfig({ root: process.cwd() })
.command([
'cm:migration',
'-n',
`${migrationPath}/create-ct/create-ct-opts.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should create content type', () => {});
});

describe('Delete field', () => {
nockBack('delete-field.json', (nockDone) => {
test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
fancy
.it('Should create content type', async() => {
await runCommand([
'cm:migration',
'-n',
`${migrationPath}/delete-field/delete-field.js`,
`${migrationPath}/create-ct/create-ct-opts.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should delete the field successfully and update content type', (ctx) => {
expect(ctx.stdout).to.contains('Successfully updated content type: foo3');
],{ root: process.cwd() })
});
});

describe('Delete field', () => {
nockBack('delete-field.json', (nockDone) => {
fancy
.it('Should delete the field successfully and update content type', async() => {
const {stdout} = await runCommand([
'cm:migration',
'-n',
`${migrationPath}/delete-field/delete-field.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],{ root: process.cwd() })
expect(stdout).to.contains('Successfully updated content type: foo3');
nockDone();
});

test
.loadConfig({ root: process.cwd() })
.stdout()
.command([
'cm:migration',
'-n',
`${migrationPath}/delete-field/delete-invalid-field.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should show error on invalid field deletion', (ctx) => {
expect(ctx.stdout).to.contains('facebook_linkss does not exist in the schema');
fancy
.it('Should show error on invalid field deletion', async() => {
const {stdout} = await runCommand([
'cm:migration',
'-n',
`${migrationPath}/delete-field/delete-invalid-field.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],{ root: process.cwd() })
expect(stdout).to.contains('facebook_linkss does not exist in the schema');
nockDone();
});
});
});

describe('wind up field test', () => {
test
.loadConfig({ root: process.cwd() })
.command([
'cm:migration',
'-n',
`${migrationPath}/edit-ct/delete-ct.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
])
.it('Should create content type', () => {});
fancy
.it('Should create content type', async() => {
await runCommand([
'cm:migration',
'-n',
`${migrationPath}/edit-ct/delete-ct.js`,
'-A',
'-k',
'bltmock9e992a923aafdmock521adc4b5b3',
],{ root: process.cwd() })
});
});
});
Loading