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

Commit e4f3473

Browse files
authored
Merge pull request #114 from mocks-server/release
Release v3.0.0
2 parents e21cdbc + 6629e36 commit e4f3473

File tree

20 files changed

+4062
-2266
lines changed

20 files changed

+4062
-2266
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"env": {
3-
"node": true
3+
"node": true,
4+
"es6": true
45
},
56
"parserOptions": {
67
"ecmaVersion": "2018",

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches:
55
- master
66
- release
7+
- pre-release
78
pull_request:
89
jobs:
910
test:

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,49 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
### Changed
1010
### Fixed
1111
### Removed
12+
### Breaking change
13+
14+
## [3.0.0] - 2021-02-17
15+
16+
### Added
17+
- feat: Expose one different method for each action.
18+
- feat: Reject promises in case of status code different to 2xx
19+
20+
### Changed
21+
- feat: Rename `apiPath` config property into `adminApiPath`
22+
- feat: Update mocks-server dependencies to v2 beta versions and adapt routes and tests.
23+
24+
### Removed
25+
- feat: Make entities private
26+
27+
### BREAKING CHANGES
28+
- Core and plugins updated to v2. Please read the [migration from v1.x guide](https://www.mocks-server.org/docs/guides-migrating-from-v1) and the [Core v2 release notes](https://github.com/mocks-server/core/releases/tag/v2.0.0) for further info.
29+
- Rename `apiPath` config property into `adminApiPath`
30+
- Removed previous entity-based methods
31+
32+
## [3.0.0-beta.2] - 2021-02-16
33+
34+
### Changed
35+
- chore(deps): Update dependencies. Adapt tests
36+
- feat: Rename `apiPath` config property into `adminApiPath`
37+
- feat: Rename `readMockCustomRoutesVariants` method into `readCustomRoutesVariants`
38+
- feat: Rename `addMockCustomRouteVariant` method into `useRouteVariant`
39+
- feat: Rename `restoreMockRoutesVariants` method into `restoreRoutesVariants`
40+
41+
## [3.0.0-beta.1] - 2021-02-15
42+
43+
### Added
44+
- feat: Expose one different method for each action.
45+
- feat: Reject promises in case of status code different to 2xx
46+
47+
### Changed
48+
- feat: Update mocks-server dependencies to v2 beta versions and adapt routes and tests.
49+
50+
### Removed
51+
- feat: Make entities private
52+
53+
### Breaking change
54+
- Removed previous entity-based methods
1255

1356
## [2.1.0] - 2020-12-26
1457

README.md

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
# Mocks-server administration api client
99

10-
This package contains methods for administrating `mocks-server` _(through the [@mocks-server/plugin-admin-api](https://github.com/mocks-server/plugin-admin-api) REST API)_.
10+
This package contains methods for administrating Mocks Server _(using the [Admin API plugin](https://github.com/mocks-server/plugin-admin-api) under the hood)_.
1111

12-
Requests to `mocks-server` are made using [cross-fetch](https://www.npmjs.com/package/cross-fetch), which makes this package compatible with browsers and nodejs environments, but, if you are going to build a browser application, you'll probably prefer to use the [@mocks-server/admin-api-client-data-provider package](https://www.npmjs.com/package/@mocks-server/admin-api-client-data-provider), which uses [@data-provider](https://github.com/data-provider), and works well with Redux, React, etc.
12+
Requests to the Mocks Server API are made using [`cross-fetch`](https://www.npmjs.com/package/cross-fetch), which makes this package compatible with browsers and nodejs environments, but, if you are going to build a browser application, you'll probably prefer to use the [`@mocks-server/admin-api-client-data-provider` package](https://www.npmjs.com/package/@mocks-server/admin-api-client-data-provider), which uses [Data Provider](https://www.data-provider.org), and works well with Redux, React, etc.
1313

1414
## Install
1515

@@ -28,51 +28,63 @@ The UMD build is also available on unpkg:
2828
2929
## Usage
3030

31-
All methods described in the [Api](#api) (expect the `config` method) return Promises when executed:
31+
All methods described in the [Api](#api) (except the `config` method) return Promises when executed:
3232

3333
```js
34-
import { about, settings } from "@mocks-server/admin-api-client";
34+
import { readAbout, readSettings, updateSettings } from "@mocks-server/admin-api-client";
3535

3636
const example = async () => {
37-
const { version } = await about.read();
38-
console.log(`Current plugin-admin-api version is ${version}`);
37+
const { version } = await readAbout();
38+
console.log(`Current Admin API plugin version is ${version}`);
3939

40-
const currentSettings = await settings.read();
41-
console.log("Current mocks-server settings are", currentSettings);
40+
const currentSettings = await readSettings();
41+
console.log("Current Mocks Server settings are", currentSettings);
4242

43-
await settings.update({
44-
behavior: "user-super-admin",
43+
await updateSettings({
44+
mock: "user-super-admin",
4545
delay: 1000
4646
});
47-
console.log("Behavior and delay changed");
47+
console.log("Mock and delay changed");
4848
};
4949

5050
example();
5151
```
5252

5353
## Api
5454

55-
* `about.read()` - Returns info about mocks-server/plugin-admin-api, such as current version.
56-
* `settings.read()` - Returns current @mocks-server settings.
57-
* `settings.update(settingsObject)` - Updates @mocks-server settings. A settings object has to be provided. Read the [@mocks-server configuration documentation](https://www.mocks-server.org/docs/configuration-options) for further info.
58-
* `behaviors.read()` - Returns collection of available behaviors.
59-
* `behavior(behaviorName).read()` - Returns an specific behavior.
60-
* `fixtures.read()` - Returns collection of available fixtures.
61-
* `fixture(fixtureId).read()` - Returns an specific fixture.
62-
* `alerts.read()` - Returns array of current alerts.
63-
* `alert(alertId).read()` - Returns an specific alert.
55+
* `readAbout()` - Returns info about the Admin API plugin, such as current version.
56+
* `readSettings()` - Returns current Mocks Server settings.
57+
* `updateSettings(settingsObject)` - Updates Mocks Server settings. A settings object has to be provided. Read the [Mocks Server configuration docs](https://www.mocks-server.org/docs/configuration-options) for further info.
58+
* `readAlerts()` - Returns array of current alerts.
59+
* `readAlert(alertId)` - Returns an specific alert.
60+
* `readMocks()` - Returns available mocks.
61+
* `readMock(id)` - Returns data of a specific mock.
62+
* `readRoutes()` - Returns available routes.
63+
* `readRoute(id)` - Returns data of a specific route.
64+
* `readRoutesVariants()` - Returns available routes variants.
65+
* `readRouteVariant(id)` - Returns data of a specific route variant.
66+
* `readCustomRoutesVariants()` - Returns current routes variants manually added to current mock.
67+
* `useRouteVariant(id)` - Sets a specific route variant to be used by current mock.
68+
* `restoreRoutesVariants()` - Restore routes variants to those defined in current mock.
69+
70+
##### Legacy methods
71+
72+
* `readBehaviors()` - Returns collection of available behaviors.
73+
* `readBehavior(behaviorName)` - Returns an specific behavior.
74+
* `readFixtures()` - Returns collection of available fixtures.
75+
* `readFixture(fixtureId)` - Returns an specific fixture.
6476

6577
## Configuration
6678

67-
By default, the client is configured to request to http://localhost:3100/admin, based in the [default options of @mocks-server](https://www.mocks-server.org/docs/configuration-options)
79+
By default, the client is configured to request to `http://localhost:3100/admin`, based in the [default options of Mocks Server](https://www.mocks-server.org/docs/configuration-options)
6880

69-
You can change both the base url of the "@mocks-server", and the base api path of the "@mocks-server/plugin-admin-api" using the `config` method:
81+
You can change both the base url of Mocks Server, and the path of the [Admin API plugin][plugin-admin-api-url] using the `config` method:
7082

7183
```js
7284
import { config } from "@mocks-server/admin-api-client";
7385

7486
config({
75-
apiPath: "/foo-admin",
87+
adminApiPath: "/foo-admin",
7688
baseUrl: "http://my-mocks-server:3000"
7789
});
7890
```

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { config } from "./src/entities";
12
export * from "./src/methods";
File renamed without changes.
File renamed without changes.
File renamed without changes.

mocks/mocks-server.config.js renamed to mocks/mocks.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = {
22
options: {
33
port: 3200,
44
log: "debug",
5+
pathLegacy: "legacy-mocks",
56
},
67
};

mocks/mocks/mocks.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = [
2+
{
3+
id: "base",
4+
routesVariants: ["get-user:1"],
5+
},
6+
{
7+
id: "user2",
8+
routesVariants: ["get-user:2"],
9+
},
10+
];

mocks/mocks/routes/users.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = [
2+
{
3+
id: "get-user",
4+
url: "/api/user",
5+
method: "GET",
6+
variants: [
7+
{
8+
id: "1",
9+
response: {
10+
status: 200,
11+
body: [{ email: "foo@foo.com" }],
12+
},
13+
},
14+
{
15+
id: "2",
16+
response: {
17+
status: 200,
18+
body: [{ email: "foo2@foo2.com" }],
19+
},
20+
},
21+
],
22+
},
23+
];

0 commit comments

Comments
 (0)