This repository has been archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6843b7d
commit 4efc891
Showing
29 changed files
with
1,444 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
Copyright 2019 Javier Brea | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
const { mocksRunner, fetch, waitForServerAndCli, TimeCounter } = require("./support/helpers"); | ||
|
||
describe("command line arguments", () => { | ||
let mocks; | ||
|
||
afterEach(async () => { | ||
await mocks.kill(); | ||
}); | ||
|
||
describe("path option", () => { | ||
it("should set mocks folder", async () => { | ||
expect.assertions(2); | ||
mocks = mocksRunner(["--path=web-tutorial"]); | ||
await waitForServerAndCli(); | ||
const users = await fetch("/api/users"); | ||
expect(users.body).toEqual([ | ||
{ id: 1, name: "John Doe" }, | ||
{ id: 2, name: "Jane Doe" }, | ||
]); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Mocks: 3")); | ||
}); | ||
}); | ||
|
||
describe("mock option", () => { | ||
describe("when not provided", () => { | ||
it("should set as current mock the first one found", async () => { | ||
expect.assertions(2); | ||
mocks = mocksRunner(["--path=web-tutorial"]); | ||
await waitForServerAndCli(); | ||
const users = await fetch("/api/users/2"); | ||
expect(users.body).toEqual({ id: 1, name: "John Doe" }); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: base")); | ||
}); | ||
}); | ||
|
||
describe("when provided and exists", () => { | ||
it("should set current mock", async () => { | ||
expect.assertions(2); | ||
mocks = mocksRunner(["--path=web-tutorial", "--mock=user-2"]); | ||
await waitForServerAndCli(); | ||
const users = await fetch("/api/users/2"); | ||
expect(users.body).toEqual({ id: 2, name: "Jane Doe" }); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: user-2")); | ||
}); | ||
}); | ||
|
||
describe("when provided and does not exist", () => { | ||
it("should display an alert", async () => { | ||
mocks = mocksRunner(["--path=web-tutorial", "--mock=foo"]); | ||
await waitForServerAndCli(); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("ALERTS")); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining('Mock "foo" was not found')); | ||
}); | ||
|
||
it("should set as current behavior the first one found", async () => { | ||
expect.assertions(3); | ||
mocks = mocksRunner(["--path=web-tutorial", "--mock=foo"]); | ||
await waitForServerAndCli(); | ||
const users = await fetch("/api/users/2"); | ||
expect(users.body).toEqual({ id: 1, name: "John Doe" }); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Using the first one found")); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: base")); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("delay option", () => { | ||
it("should set delay", async () => { | ||
expect.assertions(3); | ||
mocks = mocksRunner(["--path=web-tutorial", "--delay=2000"]); | ||
await waitForServerAndCli(); | ||
const timeCounter = new TimeCounter(); | ||
const users = await fetch("/api/users"); | ||
timeCounter.stop(); | ||
expect(users.body).toEqual([ | ||
{ id: 1, name: "John Doe" }, | ||
{ id: 2, name: "Jane Doe" }, | ||
]); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Delay: 2000")); | ||
expect(timeCounter.total).toBeGreaterThan(1999); | ||
}); | ||
}); | ||
|
||
describe("log option", () => { | ||
it("should set log level", async () => { | ||
mocks = mocksRunner(["--path=web-tutorial", "--log=debug"]); | ||
await waitForServerAndCli(); | ||
expect(mocks.currentScreen).toEqual(expect.stringContaining("Log level: debug")); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.