Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #166 from mocks-server/release
Browse files Browse the repository at this point in the history
Release v2.3.1
  • Loading branch information
javierbrea committed May 6, 2021
2 parents ec2e5bb + 18d4e39 commit dbe9dd4
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 93 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"parser": "flow"
}
],
"no-shadow": "error",
"no-undef": "error",
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
"no-only-tests/no-only-tests": [2]
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [2.3.1] - 2021-05-06

### Fixed
- fix: make body property in response not mandatory

### Changed
- chore(deps): update dependencies

## [2.3.0] - 2021-05-05

### Added
Expand Down
97 changes: 21 additions & 76 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mocks-server/core",
"version": "2.3.0",
"version": "2.3.1",
"description": "Pluggable mock server supporting multiple route variants and mocks",
"keywords": [
"mocks",
Expand Down Expand Up @@ -64,10 +64,10 @@
"@babel/preset-typescript": "7.13.0",
"cross-fetch": "3.1.4",
"cross-spawn": "7.0.3",
"eslint": "7.24.0",
"eslint-plugin-no-only-tests": "2.5.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-prettier": "3.3.1",
"eslint": "7.25.0",
"eslint-plugin-no-only-tests": "2.6.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "3.4.0",
"husky": "4.3.8",
"jest": "26.6.3",
"lint-staged": "10.5.4",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.organization=mocks-server
sonar.projectKey=mocks-server-core
sonar.projectVersion=2.3.0
sonar.projectVersion=2.3.1

sonar.javascript.file.suffixes=.js
sonar.sourceEncoding=UTF-8
Expand Down
6 changes: 3 additions & 3 deletions src/mocks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ function getRouteVariants({ routesDefinitions, addAlert, removeAlerts, routeHand
}
routeIds.push(route.id);

return route.variants.map((variant, index) => {
return route.variants.map((variant, variantIndex) => {
const variantHandler = getVariantHandler({
route,
variant,
variantIndex: index,
variantIndex,
routeHandlers,
core,
addAlert,
Expand All @@ -274,7 +274,7 @@ function getRouteVariants({ routesDefinitions, addAlert, removeAlerts, routeHand
if (variantHandler) {
if (routeVariantsIds.includes(variantHandler.id)) {
addAlert(
`${alertScope}:variant:${index}:duplicated`,
`${alertScope}:variant:${variantIndex}:duplicated`,
`Route variant with duplicated id "${variantHandler.id}" detected in route "${route.id}". It has been ignored`
);
return null;
Expand Down
12 changes: 7 additions & 5 deletions src/routes-handlers/default/DefaultRoutesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Unless required by applicable law or agreed to in writing, software distributed

const { isFunction } = require("lodash");

const FUNCTION = "function";

class DefaultRoutesHandler {
static get id() {
return "default";
Expand All @@ -28,21 +30,21 @@ class DefaultRoutesHandler {
properties: {
headers: {
type: "object",
errorMessage: 'Property "headers" should be an object',
errorMessage: 'Property "response.headers" should be an object',
},
},
required: ["status", "body"],
required: ["status"],
errorMessage: {
required: {
id: 'Should have an integer property "status"',
status: 'Should have an integer property "response.status"',
},
},
},
{
instanceof: "Function",
},
],
errorMessage: 'Property "response" should be an object or a function',
errorMessage: 'Property "response" should be a valid object or a function',
},
},
required: ["response"],
Expand Down Expand Up @@ -82,7 +84,7 @@ class DefaultRoutesHandler {

get plainResponsePreview() {
return isFunction(this._response)
? "function"
? FUNCTION
: {
body: this._response.body,
status: this._response.status,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/v2/validations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("mocks and routes validations", () => {

it("should have added an alert about route variant not valid", () => {
expect(findAlert("mocks:validation:route:1:2", core.alerts).message).toEqual(
'Variant with id "2" in route with id "get-user-variant-invalid" is invalid: Property "response" should be an object or a function'
'Variant with id "2" in route with id "get-user-variant-invalid" is invalid: Property "response" should be a valid object or a function'
);
});

Expand Down
5 changes: 4 additions & 1 deletion test/unit/Orchestrator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("Orchestrator", () => {
let coreInstance;
let legacyMocksMock;
let mocksMock;
let orchestrator;

beforeEach(() => {
sandbox = sinon.createSandbox();
Expand All @@ -33,7 +34,7 @@ describe("Orchestrator", () => {
legacyMocksMock = new LegacyMocksMock();
mocksMock = new MocksMock();
coreInstance = coreMocks.stubs.instance;
new Orchestrator(
orchestrator = new Orchestrator(
coreInstance._eventEmitter,
legacyMocksMock.stubs.instance,
serverMocks.stubs.instance,
Expand All @@ -52,10 +53,12 @@ describe("Orchestrator", () => {

describe("when settings change", () => {
it("should restart the server when port changes", async () => {
expect.assertions(2);
coreInstance._eventEmitter.on.getCall(0).args[1]({
port: 4540,
});
expect(serverMocks.stubs.instance.restart.callCount).toEqual(1);
expect(orchestrator).toBeInstanceOf(Orchestrator);
});

it("should restart the server when host changes", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mocks/validations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe("mocks validations", () => {
DefaultRoutesHandler
);
expect(errors.message).toEqual(
'Variant with id "foo-variant" in route with id "foo-route" is invalid: Property "headers" should be an object. Property "response" should be an object or a function'
'Variant with id "foo-variant" in route with id "foo-route" is invalid: Property "response.headers" should be an object. Should have an integer property "response.status". Property "response" should be a valid object or a function'
);
});

Expand Down

0 comments on commit dbe9dd4

Please sign in to comment.