Skip to content

Commit

Permalink
Add UI for sequential responses and request number response rule
Browse files Browse the repository at this point in the history
- Add new button for sequential responses, redesign the responses menu (using grid to avoid layout issues)
- add tests for both features
- Add script to migrate test data files
Closes #459
  • Loading branch information
Guillaume committed May 5, 2021
1 parent f0f9ef2 commit 7e27de5
Show file tree
Hide file tree
Showing 41 changed files with 2,318 additions and 2,959 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -43,6 +43,13 @@ Branches naming convention:
- features and enhancements: `feature/name-or-issue-number`
- bug fixes: `fix/name-or-issue-number`

## Adding migrations

When a feature or bugfix requires a change in the data model (`Environment`, `Route`, `RouteResponse`, etc.) you must add a new migration:
- Add a new migration function in the @mockoon/commons library `/src/libs/migrations.ts` file.
- Add a new test for the migration in the main repository mockoon/mockoon `/test/data/migrations/{MIGRATION_ID}/environments.json` and `/test/suites/migrations.spec.ts` files.
- Use the script `/scripts/migrate-tests.js` in the main repository in order to migrate the tests' `environments.json` samples to the latest migration. Please note that some folders/sample files marked with a `.do-not-update-files` must never be migrated.

## Run the tests

Tests are written with Spectron and you can run them using `npm run test`. These tests will also be run on each commit or pull request by CircleCI.
Expand Down
76 changes: 52 additions & 24 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -48,8 +48,8 @@
},
"dependencies": {
"@apidevtools/swagger-parser": "10.0.2",
"@mockoon/commons": "2.0.0",
"@mockoon/commons-server": "1.0.5",
"@mockoon/commons": "2.1.0",
"@mockoon/commons-server": "1.1.0",
"axios": "0.21.1",
"electron-is-dev": "2.0.0",
"electron-json-storage": "4.4.0",
Expand Down
63 changes: 63 additions & 0 deletions scripts/migrate-tests.js
@@ -0,0 +1,63 @@
const Migrations = require('@mockoon/commons').Migrations;
const { readFileSync, writeFileSync } = require('fs');
const prettier = require('prettier');
const prettierConfig = require('../package.json').prettier;

/**
* Use this script to migrate the tests sample environments. See ../test/data/README.md for more information.
*/

const files = [
'./test/data/basic-data/environments.json',
'./test/data/environment-logs/environments.json',
'./test/data/export/environments.json',
'./test/data/export-openapi/environments.json',
'./test/data/headers/environments.json',
'./test/data/import/environments.json',
'./test/data/import/openapi/references/aws-cloudfront-v3.json',
'./test/data/import/openapi/references/aws-server-v3.json',
'./test/data/import/openapi/references/custom-schema-no-prefix-v2.json',
'./test/data/import/openapi/references/custom-schema-no-prefix-v3.json',
'./test/data/import/openapi/references/custom-schema-v2.json',
'./test/data/import/openapi/references/custom-schema-v3.json',
'./test/data/import/openapi/references/datagov-v2.json',
'./test/data/import/openapi/references/giphy-v2.json',
'./test/data/import/openapi/references/github-v2.json',
'./test/data/import/openapi/references/petstore-v2.json',
'./test/data/import/openapi/references/petstore-v3.json',
'./test/data/import/openapi/references/shutterstock-v3.json',
'./test/data/import/openapi/references/slack-v2.json',
'./test/data/import/openapi/references/youtube-v3.json',
'./test/data/proxy/environments.json',
'./test/data/responses-rules/environments.json',
'./test/data/settings/environments.json',
'./test/data/templating/environments.json',
'./test/data/ui/environments.json'
];

files.forEach((file) => {
const environments = JSON.parse(readFileSync(file).toString());

console.log(`Starting migrating ${file}`);

environments.forEach((environment) => {
Migrations.forEach((migration) => {
if (migration.id > environment.lastMigration) {
migration.migrationFunction(environment);
environment.lastMigration = migration.id;
}
});
});

writeFileSync(
file,
prettier.format(
JSON.stringify(environments),
Object.assign(prettierConfig, {
parser: 'json'
})
)
);

console.log(`Finished migrating ${file}`);
});

0 comments on commit 7e27de5

Please sign in to comment.