Skip to content

Commit 7479b1b

Browse files
Merge pull request #45 from contentstack/develop
v1.3.0
2 parents f3c06c4 + c47a5cd commit 7479b1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2068
-112
lines changed

.DS_Store

-6 KB
Binary file not shown.

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"root": true,
3+
"env": {
4+
"browser": true,
5+
"es2021": true,
6+
"node": true
7+
},
38
"parser": "@typescript-eslint/parser",
49
"plugins": ["@typescript-eslint"],
510
"extends": [

.github/workflows/unit-test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: App SDK CI - Unit Testing
5+
6+
on:
7+
push:
8+
branches: [master]
9+
10+
pull_request:
11+
types: [opened, synchronize, reopened]
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [14.x]
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v2
24+
with:
25+
node-version: '14.x'
26+
27+
- name: Use Node.js
28+
uses: actions/setup-node@v2
29+
with:
30+
node-version: '14.x'
31+
32+
- name: Install deps
33+
run: npm ci
34+
35+
- name: Run unit test
36+
run: npm run test

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ storybook-static
128128
tmp/
129129
temp/
130130

131-
dist/
131+
132+
133+
.DS_Store
132134

133135
### vscode ###
134136
.vscode/*

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm test

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Contentstack
3+
Copyright (c) 2022-2023 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ npm install @contentstack/app-sdk
1313
Alternatively, you can use the following command within the script tag to install the App SDK:
1414

1515
```html
16-
<script src="https://unpkg.com/@contentstack/app-sdk@^1.2/dist/index.js"></script>
16+
<script src="https://unpkg.com/@contentstack/app-sdk@^1.3.0/dist/index.js"></script>
1717
```
1818

1919
### Initializing the App SDK

__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)