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

Commit c947d94

Browse files
committed
feat: rename methods
1 parent e11de7b commit c947d94

File tree

7 files changed

+67
-41
lines changed

7 files changed

+67
-41
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Removed
1212
### Breaking change
1313

14-
## [3.0.0-beta.1] - 2021-01-15
14+
## [3.0.0-beta.2] - 2021-02-16
15+
16+
### Changed
17+
- chore(deps): Update depedencies. Adapt tests
18+
- feat: Rename `apiPath` config property into `adminApiPath`
19+
- feat: Rename `readMockCustomRoutesVariants` method into `readCustomRoutesVariants`
20+
- feat: Rename `addMockCustomRouteVariant` method into `useRouteVariant`
21+
- feat: Rename `restoreMockRoutesVariants` method into `restoreRoutesVariants`
22+
23+
## [3.0.0-beta.1] - 2021-02-15
1524

1625
### Added
1726
- feat: Expose one different method for each action.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ example();
6363
* `readRoute(id)` - Returns data of a specific route.
6464
* `readRoutesVariants()` - Returns available routes variants.
6565
* `readRouteVariant(id)` - Returns data of a specific route variant.
66-
* `readMockCustomRoutesVariants()` - Returns current routes variants manually added to current mock.
67-
* `addMockCustomRouteVariant(id)` - Add a route variant to current mock.
68-
* `restoreMockRoutesVariants()` - Restore current mock original routes variants.
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.
6969

7070
##### Legacy methods
7171

@@ -78,13 +78,13 @@ example();
7878

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

81-
You can change both the base url of Mocks Server, and the base api path of the Admin API plugin 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:
8282

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

8686
config({
87-
apiPath: "/foo-admin",
87+
adminApiPath: "/foo-admin",
8888
baseUrl: "http://my-mocks-server:3000"
8989
});
9090
```

mocks/package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"mocks:ci": "mocks-server --no-cli"
88
},
99
"devDependencies": {
10-
"@mocks-server/main": "2.0.0-beta.1"
10+
"@mocks-server/main": "2.0.0-beta.2"
1111
}
1212
}

src/entities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "@mocks-server/admin-api-paths";
1616

1717
const DEFAULT_OPTIONS = {
18-
apiPath: DEFAULT_BASE_PATH,
18+
adminApiPath: DEFAULT_BASE_PATH,
1919
baseUrl: "http://localhost:3100",
2020
};
2121

@@ -46,7 +46,7 @@ class Fetcher {
4646
}
4747

4848
get url() {
49-
return `${configuration.baseUrl}${configuration.apiPath}${this._url}${this._id}`;
49+
return `${configuration.baseUrl}${configuration.adminApiPath}${this._url}${this._id}`;
5050
}
5151

5252
_read() {

src/methods.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ export function readRouteVariant(id) {
6060
return routeVariant(id).read();
6161
}
6262

63-
export function readMockCustomRoutesVariants() {
63+
export function readCustomRoutesVariants() {
6464
return mockCustomRoutesVariants.read();
6565
}
6666

67-
export function addMockCustomRouteVariant(id) {
67+
export function useRouteVariant(id) {
6868
return mockCustomRoutesVariants.create({
6969
id,
7070
});
7171
}
7272

73-
export function restoreMockRoutesVariants() {
73+
export function restoreRoutesVariants() {
7474
return mockCustomRoutesVariants.delete();
7575
}
7676

test/index.spec.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import {
1212
readRoute,
1313
readRoutesVariants,
1414
readRouteVariant,
15-
readMockCustomRoutesVariants,
16-
addMockCustomRouteVariant,
17-
restoreMockRoutesVariants,
15+
readCustomRoutesVariants,
16+
useRouteVariant,
17+
restoreRoutesVariants,
1818
// legacy
1919
readBehaviors,
2020
readBehavior,
@@ -182,16 +182,31 @@ describe("react-admin-client methods used with node", () => {
182182
it("should return mocks", async () => {
183183
const mocks = await readMocks();
184184
expect(mocks).toEqual([
185-
{ id: "base", routesVariants: ["get-user:1"] },
186-
{ id: "user2", routesVariants: ["get-user:2"] },
185+
{
186+
id: "base",
187+
from: null,
188+
routesVariants: ["get-user:1"],
189+
appliedRoutesVariants: ["get-user:1"],
190+
},
191+
{
192+
id: "user2",
193+
from: null,
194+
routesVariants: ["get-user:2"],
195+
appliedRoutesVariants: ["get-user:2"],
196+
},
187197
]);
188198
});
189199
});
190200

191201
describe("when reading mock", () => {
192202
it("should return mock data", async () => {
193203
const mock = await readMock("base");
194-
expect(mock).toEqual({ id: "base", routesVariants: ["get-user:1"] });
204+
expect(mock).toEqual({
205+
id: "base",
206+
from: null,
207+
routesVariants: ["get-user:1"],
208+
appliedRoutesVariants: ["get-user:1"],
209+
});
195210
});
196211
});
197212

@@ -201,6 +216,7 @@ describe("react-admin-client methods used with node", () => {
201216
expect(data).toEqual([
202217
{
203218
id: "get-user",
219+
delay: null,
204220
url: "/api/user",
205221
method: "GET",
206222
variants: ["get-user:1", "get-user:2"],
@@ -209,11 +225,12 @@ describe("react-admin-client methods used with node", () => {
209225
});
210226
});
211227

212-
describe("when reading mock", () => {
213-
it("should return mock data", async () => {
228+
describe("when reading route", () => {
229+
it("should return route data", async () => {
214230
const mock = await readRoute("get-user");
215231
expect(mock).toEqual({
216232
id: "get-user",
233+
delay: null,
217234
url: "/api/user",
218235
method: "GET",
219236
variants: ["get-user:1", "get-user:2"],
@@ -258,26 +275,26 @@ describe("react-admin-client methods used with node", () => {
258275

259276
describe("mock custom route variants", () => {
260277
it("should be empty", async () => {
261-
const data = await readMockCustomRoutesVariants();
278+
const data = await readCustomRoutesVariants();
262279
expect(data).toEqual([]);
263280
});
264281

265282
it("should be able to add one", async () => {
266-
await addMockCustomRouteVariant("get-user:2");
267-
const data = await readMockCustomRoutesVariants();
283+
await useRouteVariant("get-user:2");
284+
const data = await readCustomRoutesVariants();
268285
expect(data).toEqual(["get-user:2"]);
269286
});
270287

271288
it("should reject if route variant don't exist", async () => {
272289
expect.assertions(1);
273-
await addMockCustomRouteVariant("foo").catch((err) => {
290+
await useRouteVariant("foo").catch((err) => {
274291
expect(err.message).toEqual('Route variant with id "foo" was not found');
275292
});
276293
});
277294

278295
it("should be empty after restoring them to the mock defaults", async () => {
279-
await restoreMockRoutesVariants();
280-
const data = await readMockCustomRoutesVariants();
296+
await restoreRoutesVariants();
297+
const data = await readCustomRoutesVariants();
281298
expect(data).toEqual([]);
282299
});
283300
});

0 commit comments

Comments
 (0)