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 #114 from mocks-server/release
Browse files Browse the repository at this point in the history
Release v3.0.0
  • Loading branch information
javierbrea authored Feb 17, 2021
2 parents e21cdbc + 6629e36 commit e4f3473
Show file tree
Hide file tree
Showing 20 changed files with 4,062 additions and 2,266 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"node": true
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": "2018",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- master
- release
- pre-release
pull_request:
jobs:
test:
Expand Down
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,49 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
### Fixed
### Removed
### Breaking change

## [3.0.0] - 2021-02-17

### Added
- feat: Expose one different method for each action.
- feat: Reject promises in case of status code different to 2xx

### Changed
- feat: Rename `apiPath` config property into `adminApiPath`
- feat: Update mocks-server dependencies to v2 beta versions and adapt routes and tests.

### Removed
- feat: Make entities private

### BREAKING CHANGES
- 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.
- Rename `apiPath` config property into `adminApiPath`
- Removed previous entity-based methods

## [3.0.0-beta.2] - 2021-02-16

### Changed
- chore(deps): Update dependencies. Adapt tests
- feat: Rename `apiPath` config property into `adminApiPath`
- feat: Rename `readMockCustomRoutesVariants` method into `readCustomRoutesVariants`
- feat: Rename `addMockCustomRouteVariant` method into `useRouteVariant`
- feat: Rename `restoreMockRoutesVariants` method into `restoreRoutesVariants`

## [3.0.0-beta.1] - 2021-02-15

### Added
- feat: Expose one different method for each action.
- feat: Reject promises in case of status code different to 2xx

### Changed
- feat: Update mocks-server dependencies to v2 beta versions and adapt routes and tests.

### Removed
- feat: Make entities private

### Breaking change
- Removed previous entity-based methods

## [2.1.0] - 2020-12-26

Expand Down
58 changes: 35 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# Mocks-server administration api client

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)_.
This package contains methods for administrating Mocks Server _(using the [Admin API plugin](https://github.com/mocks-server/plugin-admin-api) under the hood)_.

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.
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.

## Install

Expand All @@ -28,51 +28,63 @@ The UMD build is also available on unpkg:
## Usage

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

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

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

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

await settings.update({
behavior: "user-super-admin",
await updateSettings({
mock: "user-super-admin",
delay: 1000
});
console.log("Behavior and delay changed");
console.log("Mock and delay changed");
};

example();
```

## Api

* `about.read()` - Returns info about mocks-server/plugin-admin-api, such as current version.
* `settings.read()` - Returns current @mocks-server settings.
* `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.
* `behaviors.read()` - Returns collection of available behaviors.
* `behavior(behaviorName).read()` - Returns an specific behavior.
* `fixtures.read()` - Returns collection of available fixtures.
* `fixture(fixtureId).read()` - Returns an specific fixture.
* `alerts.read()` - Returns array of current alerts.
* `alert(alertId).read()` - Returns an specific alert.
* `readAbout()` - Returns info about the Admin API plugin, such as current version.
* `readSettings()` - Returns current Mocks Server settings.
* `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.
* `readAlerts()` - Returns array of current alerts.
* `readAlert(alertId)` - Returns an specific alert.
* `readMocks()` - Returns available mocks.
* `readMock(id)` - Returns data of a specific mock.
* `readRoutes()` - Returns available routes.
* `readRoute(id)` - Returns data of a specific route.
* `readRoutesVariants()` - Returns available routes variants.
* `readRouteVariant(id)` - Returns data of a specific route variant.
* `readCustomRoutesVariants()` - Returns current routes variants manually added to current mock.
* `useRouteVariant(id)` - Sets a specific route variant to be used by current mock.
* `restoreRoutesVariants()` - Restore routes variants to those defined in current mock.

##### Legacy methods

* `readBehaviors()` - Returns collection of available behaviors.
* `readBehavior(behaviorName)` - Returns an specific behavior.
* `readFixtures()` - Returns collection of available fixtures.
* `readFixture(fixtureId)` - Returns an specific fixture.

## Configuration

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)
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)

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:
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:

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

config({
apiPath: "/foo-admin",
adminApiPath: "/foo-admin",
baseUrl: "http://my-mocks-server:3000"
});
```
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { config } from "./src/entities";
export * from "./src/methods";
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions mocks/mocks-server.config.js → mocks/mocks.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
options: {
port: 3200,
log: "debug",
pathLegacy: "legacy-mocks",
},
};
10 changes: 10 additions & 0 deletions mocks/mocks/mocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = [
{
id: "base",
routesVariants: ["get-user:1"],
},
{
id: "user2",
routesVariants: ["get-user:2"],
},
];
23 changes: 23 additions & 0 deletions mocks/mocks/routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = [
{
id: "get-user",
url: "/api/user",
method: "GET",
variants: [
{
id: "1",
response: {
status: 200,
body: [{ email: "[email protected]" }],
},
},
{
id: "2",
response: {
status: 200,
body: [{ email: "[email protected]" }],
},
},
],
},
];
Loading

0 comments on commit e4f3473

Please sign in to comment.