|
| 1 | +/* |
| 2 | +Copyright 2020 Javier Brea |
| 3 | +
|
| 4 | +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 |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +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. |
| 9 | +*/ |
| 10 | + |
| 11 | +const { startServer, stopServer, request, fixturesFolder, wait } = require("./support/utils"); |
| 12 | + |
| 13 | +describe("stop plugin", () => { |
| 14 | + let server; |
| 15 | + beforeAll(async () => { |
| 16 | + server = await startServer("web-tutorial"); |
| 17 | + }); |
| 18 | + |
| 19 | + afterAll(async () => { |
| 20 | + await stopServer(server); |
| 21 | + }); |
| 22 | + |
| 23 | + describe("when started", () => { |
| 24 | + it("should return current settings", async () => { |
| 25 | + const response = await request("/admin/settings"); |
| 26 | + expect(response).toEqual({ |
| 27 | + behavior: "standard", |
| 28 | + path: fixturesFolder("web-tutorial"), |
| 29 | + delay: 0, |
| 30 | + host: "0.0.0.0", |
| 31 | + port: 3100, |
| 32 | + watch: false, |
| 33 | + log: "silly", |
| 34 | + adminApiPath: "/admin", |
| 35 | + adminApiDeprecatedPaths: true, |
| 36 | + }); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + describe("when stopped", () => { |
| 41 | + it("should respond not found when requesting setting", async () => { |
| 42 | + await server._stopPlugins(); |
| 43 | + const response = await request("/admin/settings", { |
| 44 | + resolveWithFullResponse: true, |
| 45 | + simple: false, |
| 46 | + }); |
| 47 | + expect(response.statusCode).toEqual(404); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should respond to mocks requests", async () => { |
| 51 | + await server._stopPlugins(); |
| 52 | + const response = await request("/api/users"); |
| 53 | + expect(response).toEqual([ |
| 54 | + { |
| 55 | + id: 1, |
| 56 | + name: "John Doe", |
| 57 | + }, |
| 58 | + { |
| 59 | + id: 2, |
| 60 | + name: "Jane Doe", |
| 61 | + }, |
| 62 | + ]); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe("when behavior is changed", () => { |
| 67 | + it("should respond with new behavior", async () => { |
| 68 | + server.settings.set("behavior", "user2"); |
| 69 | + await wait(1000); |
| 70 | + const response = await request("/api/users/2"); |
| 71 | + expect(response).toEqual({ |
| 72 | + id: 2, |
| 73 | + name: "Jane Doe", |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should have not started the plugin", async () => { |
| 78 | + await server._stopPlugins(); |
| 79 | + const response = await request("/admin/settings", { |
| 80 | + resolveWithFullResponse: true, |
| 81 | + simple: false, |
| 82 | + }); |
| 83 | + expect(response.statusCode).toEqual(404); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + describe("when plugins are started", () => { |
| 88 | + it("should respond with same behavior", async () => { |
| 89 | + await server._startPlugins(); |
| 90 | + const response = await request("/api/users/2"); |
| 91 | + expect(response).toEqual({ |
| 92 | + id: 2, |
| 93 | + name: "Jane Doe", |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + it("should have started the plugin", async () => { |
| 98 | + const response = await request("/admin/settings"); |
| 99 | + expect(response).toEqual({ |
| 100 | + behavior: "user2", |
| 101 | + path: fixturesFolder("web-tutorial"), |
| 102 | + delay: 0, |
| 103 | + host: "0.0.0.0", |
| 104 | + port: 3100, |
| 105 | + watch: false, |
| 106 | + log: "silly", |
| 107 | + adminApiPath: "/admin", |
| 108 | + adminApiDeprecatedPaths: true, |
| 109 | + }); |
| 110 | + }); |
| 111 | + }); |
| 112 | +}); |
0 commit comments