|
1 | | -import { mockLdpContainer } from "./mockResponses"; |
| 1 | +import { mockLdpContainer, mockTurtleDocument } from "./mockResponses"; |
2 | 2 |
|
3 | 3 | describe("mockResponses", () => { |
| 4 | + describe("mockTurtleResponse", () => { |
| 5 | + it("mocks a turtle document body", async () => { |
| 6 | + const fetch = jest.fn(); |
| 7 | + mockTurtleDocument( |
| 8 | + fetch, |
| 9 | + "http://document.test/", |
| 10 | + `<> <> "Some content" .`, |
| 11 | + ); |
| 12 | + const result = await fetch("http://document.test/", {}); |
| 13 | + expect(await result.text()).toEqual('<> <> "Some content" .'); |
| 14 | + }); |
| 15 | + |
| 16 | + it("mocks standard turtle document headers", async () => { |
| 17 | + const fetch = jest.fn(); |
| 18 | + mockTurtleDocument( |
| 19 | + fetch, |
| 20 | + "http://document.test/", |
| 21 | + `<> <> "Some content" .`, |
| 22 | + ); |
| 23 | + const result: Response = await fetch("http://document.test/", {}); |
| 24 | + expect(result.headers.get("Content-Type")).toEqual("text/turtle"); |
| 25 | + expect(result.headers.get("Link")).toEqual( |
| 26 | + '<http://www.w3.org/ns/ldp#Resource>; rel="type"', |
| 27 | + ); |
| 28 | + expect(result.headers.get("Wac-Allow")).toEqual( |
| 29 | + 'user="read write append control",public="read"', |
| 30 | + ); |
| 31 | + expect(result.headers.get("Accept-Patch")).toEqual("text/n3"); |
| 32 | + }); |
| 33 | + |
| 34 | + it("mocks additional headers as provided", async () => { |
| 35 | + const fetch = jest.fn(); |
| 36 | + mockTurtleDocument( |
| 37 | + fetch, |
| 38 | + "http://document.test/", |
| 39 | + `<> <> "Some content" .`, |
| 40 | + { |
| 41 | + "X-My-Header": "MyValue", |
| 42 | + }, |
| 43 | + ); |
| 44 | + const result: Response = await fetch("http://document.test/", {}); |
| 45 | + expect(result.headers.get("X-My-Header")).toEqual("MyValue"); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
4 | 49 | describe("mockLdpContainer", () => { |
5 | 50 | it("mocks a container without contents", async () => { |
6 | 51 | const fetch = jest.fn(); |
|
0 commit comments