| 1 |
import { Server } from "miragejs"; |
| 2 |
|
| 3 |
describe("Integration | Server | Get full path", function () { |
| 4 |
let server; |
| 5 |
|
| 6 |
beforeEach(function () { |
| 7 |
server = new Server({ |
| 8 |
environment: "test", |
| 9 |
}); |
| 10 |
}); |
| 11 |
|
| 12 |
afterEach(function () { |
| 13 |
server.shutdown(); |
| 14 |
}); |
| 15 |
|
| 16 |
test("it works with a configured namespace with a leading slash", () => { |
| 17 |
expect.assertions(1); |
| 18 |
server.namespace = "/api"; |
| 19 |
|
| 20 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 21 |
"/api/contacts" |
| 22 |
); |
| 23 |
}); |
| 24 |
|
| 25 |
test("it works with a configured namespace with a trailing slash", () => { |
| 26 |
expect.assertions(1); |
| 27 |
server.namespace = "api/"; |
| 28 |
|
| 29 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 30 |
"/api/contacts" |
| 31 |
); |
| 32 |
}); |
| 33 |
|
| 34 |
test("it works with a configured namespace without a leading slash", () => { |
| 35 |
expect.assertions(1); |
| 36 |
server.namespace = "api"; |
| 37 |
|
| 38 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 39 |
"/api/contacts" |
| 40 |
); |
| 41 |
}); |
| 42 |
|
| 43 |
test("it works with a configured namespace is an empty string", () => { |
| 44 |
expect.assertions(1); |
| 45 |
server.namespace = ""; |
| 46 |
|
| 47 |
expect(server.interceptor._getFullPath("/contacts")).toEqual("/contacts"); |
| 48 |
}); |
| 49 |
|
| 50 |
test("it works with a configured urlPrefix with a trailing slash", () => { |
| 51 |
expect.assertions(1); |
| 52 |
server.urlPrefix = "http://localhost:3000/"; |
| 53 |
|
| 54 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 55 |
"http://localhost:3000/contacts" |
| 56 |
); |
| 57 |
}); |
| 58 |
|
| 59 |
test("it works with a configured urlPrefix without a trailing slash", () => { |
| 60 |
expect.assertions(1); |
| 61 |
server.urlPrefix = "http://localhost:3000"; |
| 62 |
|
| 63 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 64 |
"http://localhost:3000/contacts" |
| 65 |
); |
| 66 |
}); |
| 67 |
|
| 68 |
test("it works with a configured urlPrefix as an empty string", () => { |
| 69 |
expect.assertions(1); |
| 70 |
server.urlPrefix = ""; |
| 71 |
|
| 72 |
expect(server.interceptor._getFullPath("/contacts")).toEqual("/contacts"); |
| 73 |
}); |
| 74 |
|
| 75 |
test("it works with a configured namespace and a urlPrefix", () => { |
| 76 |
expect.assertions(1); |
| 77 |
server.namespace = "api"; |
| 78 |
server.urlPrefix = "http://localhost:3000"; |
| 79 |
|
| 80 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 81 |
"http://localhost:3000/api/contacts" |
| 82 |
); |
| 83 |
}); |
| 84 |
|
| 85 |
test("it works with a configured namespace with a leading slash and a urlPrefix", () => { |
| 86 |
expect.assertions(1); |
| 87 |
server.namespace = "/api"; |
| 88 |
server.urlPrefix = "http://localhost:3000"; |
| 89 |
|
| 90 |
expect(server.interceptor._getFullPath("/contacts")).toEqual( |
| 91 |
"http://localhost:3000/api/contacts" |
| 92 |
); |
| 93 |
}); |
| 94 |
|
| 95 |
test("it works with a configured namespace and a urlPrefix as empty strings", () => { |
| 96 |
expect.assertions(1); |
| 97 |
server.namespace = ""; |
| 98 |
server.urlPrefix = ""; |
| 99 |
|
| 100 |
expect(server.interceptor._getFullPath("/contacts")).toEqual("/contacts"); |
| 101 |
}); |
| 102 |
}); |