Skip to content

Commit 9187b84

Browse files
Merge pull request #42 from contentstack/CS-32161/cross-stack-reference
CS 32161:cross stack reference
2 parents d0df9df + 96470bd commit 9187b84

27 files changed

+755
-126
lines changed

__test__/data/testData.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,26 @@
7474
"name": "Extension Demo",
7575
"org_uid": "xxxxxx",
7676
"api_key": "xxxxxx",
77+
"master_locale": "en-us",
78+
"is_asset_download_public": true,
7779
"owner_uid": "xxxxxxx",
78-
"enable_presence": true,
80+
"user_uids": ["xxxxxxx"],
7981
"settings": {
8082
"version": "2017-10-14",
8183
"webhook_enabled": true
8284
},
85+
"branches": [
86+
{
87+
"api_key": "xxxxxx",
88+
"uid": "main_branch",
89+
"source": "",
90+
"alias": [
91+
{
92+
"uid": "branch_alias"
93+
}
94+
]
95+
}
96+
],
8397
"SYS_ACL": {
8498
"others": {
8599
"invite": false,

__test__/metadata.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)