|
| 1 | +import Metadata from "../src/metadata"; |
| 2 | + |
| 3 | +describe("Metadata", () => { |
| 4 | + let connection: { sendToParent: typeof jest.fn }; |
| 5 | + let sendToParent: typeof jest.fn; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + sendToParent = jest.fn().mockReturnValue(Promise.resolve({ data: {} })); |
| 9 | + connection = { sendToParent: sendToParent }; |
| 10 | + jest.spyOn(connection, "sendToParent"); |
| 11 | + }); |
| 12 | + |
| 13 | + test("should retrieve metadata", async () => { |
| 14 | + const metadata = new Metadata(connection); |
| 15 | + const uid = "some-uid"; |
| 16 | + const metadataConfig = { uid }; |
| 17 | + await metadata.retrieveMetaData(metadataConfig); |
| 18 | + expect(connection.sendToParent).toHaveBeenCalledWith("stackQuery", { |
| 19 | + uid, |
| 20 | + action: "getMetadata", |
| 21 | + payload: { |
| 22 | + metadata: { |
| 23 | + uid, |
| 24 | + }, |
| 25 | + }, |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + test("should retrieve all metadata", async () => { |
| 30 | + const metadata = new Metadata(connection); |
| 31 | + const metadataParams = { some: "config" }; |
| 32 | + await metadata.retrieveAllMetaData(metadataParams); |
| 33 | + expect(connection.sendToParent).toHaveBeenCalledWith("stackQuery", { |
| 34 | + action: "getAllMetadata", |
| 35 | + params: metadataParams, |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + test("should update metadata", async () => { |
| 40 | + const metadata = new Metadata(connection); |
| 41 | + const uid = "some-uid"; |
| 42 | + const metadataConfig = { uid, some: "config" }; |
| 43 | + await metadata.updateMetaData(metadataConfig); |
| 44 | + expect(connection.sendToParent).toHaveBeenCalledWith("stackQuery", { |
| 45 | + uid, |
| 46 | + action: "updateMetadata", |
| 47 | + payload: { |
| 48 | + metadata: { |
| 49 | + ...metadataConfig, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + test("should delete metadata", async () => { |
| 56 | + const metadata = new Metadata(connection); |
| 57 | + const uid = "some-uid"; |
| 58 | + const metadataConfig = { uid }; |
| 59 | + await metadata.deleteMetaData(metadataConfig); |
| 60 | + expect(connection.sendToParent).toHaveBeenCalledWith("stackQuery", { |
| 61 | + uid, |
| 62 | + action: "deleteMetadata", |
| 63 | + payload: { |
| 64 | + metadata: { |
| 65 | + uid, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments