Skip to content

Commit cf2740e

Browse files
Merge pull request #56 from contentstack/develop
v1.4.0-beta.0
2 parents 7479b1b + d1762aa commit cf2740e

Some content is hidden

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

53 files changed

+19412
-5225
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"node": true
77
},
88
"parser": "@typescript-eslint/parser",
9-
"plugins": ["@typescript-eslint"],
9+
"plugins": ["@typescript-eslint", "only-warn"],
1010
"extends": [
1111
"eslint:recommended",
1212
"plugin:@typescript-eslint/eslint-recommended",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow will run tet using node and then publish a beta version of the package in the NPM and GitHub registry
2+
3+
name: Beta release
4+
5+
on:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 14
16+
- run: npm ci
17+
- run: npm test
18+
name: Build and test
19+
20+
publish-gpr:
21+
needs: build
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: actions/setup-node@v3
29+
with:
30+
node-version: 14
31+
registry-url: https://npm.pkg.github.com/
32+
- run: npm ci
33+
- run: npm publish --tag beta
34+
env:
35+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
36+
name: Publish to GitHub
37+
38+
publish-npm:
39+
needs: build
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v2
43+
- uses: actions/setup-node@v2
44+
with:
45+
node-version: 16
46+
registry-url: https://registry.npmjs.org/
47+
- run: npm ci
48+
- run: npm publish --tag beta
49+
env:
50+
NODE_AUTH_TOKEN: ${{secrets.APP_SDK_AUTOMATION}}
51+
name: Publish to NPM
52+
53+
54+

__test__/entry.test.ts

Lines changed: 96 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ describe("Entry", () => {
2525
};
2626

2727
jest.spyOn(emitter, "on");
28+
29+
const changedData = JSON.parse(JSON.stringify(testData));
30+
changedData.entry.title = "changed title";
31+
2832
// @ts-ignore
29-
entry = new Entry({ data: testData }, connection, emitter);
33+
entry = new Entry({ data: testData, changedData }, connection, emitter);
3034
});
3135

3236
it("init", (done) => {
@@ -50,69 +54,99 @@ describe("Entry", () => {
5054
expect(testData.entry).toEqual(entry.getData());
5155
});
5256

53-
it("getField undefined", function () {
54-
const uid = "group1.group";
55-
const schema = entry.content_type.schema[5].schema[0];
56-
const field = entry.getField(uid);
57-
58-
expect(field.uid).toEqual(uid);
59-
expect(field.data_type).toEqual(schema.data_type);
60-
expect(field.schema).toEqual(schema);
61-
});
62-
63-
it("getField modular blocks, get complete block", function () {
64-
const uid = "modular_blocks.0";
65-
const schema = entry.content_type.schema[6].blocks[2];
66-
const field = entry.getField(uid);
67-
expect(field.uid).toEqual(uid);
68-
expect(field.data_type).toEqual(schema.data_type);
69-
expect(field.schema).toEqual(schema);
70-
});
71-
72-
it("getField modular blocks, get single block", function () {
73-
const uid = "modular_blocks.0.banner";
74-
const schema = entry.content_type.schema[6].blocks[2].schema;
75-
const field = entry.getField(uid);
76-
expect(field.uid).toEqual(uid);
77-
expect(field.data_type).toEqual(schema.data_type);
78-
expect(field.schema).toEqual(schema);
79-
});
80-
81-
it("getField modular blocks, get block field", function () {
82-
const uid = "modular_blocks.0.banner.banner_image";
83-
const schema = entry.content_type.schema[6].blocks[2].schema[0];
84-
const field = entry.getField(uid);
85-
expect(field.uid).toEqual(uid);
86-
expect(field.data_type).toEqual(schema.data_type);
87-
expect(field.schema).toEqual(schema);
88-
});
89-
90-
it("getField global field", function () {
91-
const uid = "global_field.single_line";
92-
const schema = entry.content_type.schema[7].schema[0];
93-
const field = entry.getField(uid);
94-
expect(field.uid).toEqual(uid);
95-
expect(field.data_type).toEqual(schema.data_type);
96-
expect(field.schema).toEqual(schema);
97-
});
57+
describe("getField", () => {
58+
it("getField undefined", function () {
59+
const uid = "group1.group";
60+
const schema = entry.content_type.schema[5].schema[0];
61+
const field = entry.getField(uid);
62+
63+
expect(field.uid).toEqual(uid);
64+
expect(field.data_type).toEqual(schema.data_type);
65+
expect(field.schema).toEqual(schema);
66+
});
67+
68+
it("getField modular blocks, get complete block", function () {
69+
const uid = "modular_blocks.0";
70+
const schema = entry.content_type.schema[6].blocks[2];
71+
const field = entry.getField(uid);
72+
expect(field.uid).toEqual(uid);
73+
expect(field.data_type).toEqual(schema.data_type);
74+
expect(field.schema).toEqual(schema);
75+
});
76+
77+
it("getField modular blocks, get single block", function () {
78+
const uid = "modular_blocks.0.banner";
79+
const schema = entry.content_type.schema[6].blocks[2].schema;
80+
const field = entry.getField(uid);
81+
expect(field.uid).toEqual(uid);
82+
expect(field.data_type).toEqual(schema.data_type);
83+
expect(field.schema).toEqual(schema);
84+
});
85+
86+
it("getField modular blocks, get block field", function () {
87+
const uid = "modular_blocks.0.banner.banner_image";
88+
const schema = entry.content_type.schema[6].blocks[2].schema[0];
89+
const field = entry.getField(uid);
90+
expect(field.uid).toEqual(uid);
91+
expect(field.data_type).toEqual(schema.data_type);
92+
expect(field.schema).toEqual(schema);
93+
});
94+
95+
it("getField global field", function () {
96+
const uid = "global_field.single_line";
97+
const schema = entry.content_type.schema[7].schema[0];
98+
const field = entry.getField(uid);
99+
expect(field.uid).toEqual(uid);
100+
expect(field.data_type).toEqual(schema.data_type);
101+
expect(field.schema).toEqual(schema);
102+
});
103+
104+
it("getField multiple group", function () {
105+
const uid = "group.group.group.0.single_line";
106+
const schema =
107+
entry.content_type.schema[4].schema[0].schema[0].schema[0];
108+
const field = entry.getField(uid);
109+
expect(field.uid).toEqual(uid);
110+
expect(field.data_type).toEqual(schema.data_type);
111+
expect(field.schema).toEqual(schema);
112+
});
113+
114+
it("getField group", function () {
115+
const uid = "group.group.group";
116+
const schema = entry.content_type.schema[4].schema[0].schema[0];
117+
const field = entry.getField(uid);
118+
expect(field.uid).toEqual(uid);
119+
expect(field.data_type).toEqual(schema.data_type);
120+
expect(field.schema).toEqual(schema);
121+
});
122+
123+
it("should use unsaved schema if user set options.useUnsavedSchema = true", () => {
124+
const uid = "title";
125+
const field = entry.getField(uid, { useUnsavedSchema: true });
126+
const schema = entry.content_type.schema[0];
127+
expect(field.uid).toBe(uid);
128+
expect(field.schema).toEqual(schema);
129+
expect(field.data_type).toEqual(schema.data_type);
130+
131+
});
132+
it("should use custom Field instance if internal flag is set", () => {
133+
const fieldInstance = jest.fn();
134+
entry = new Entry(
135+
// @ts-ignore
136+
{ data: testData },
137+
connection,
138+
emitter,
139+
{
140+
_internalFlags: {
141+
FieldInstance: fieldInstance,
142+
},
143+
}
144+
);
98145

99-
it("getField multiple group", function () {
100-
const uid = "group.group.group.0.single_line";
101-
const schema =
102-
entry.content_type.schema[4].schema[0].schema[0].schema[0];
103-
const field = entry.getField(uid);
104-
expect(field.uid).toEqual(uid);
105-
expect(field.data_type).toEqual(schema.data_type);
106-
expect(field.schema).toEqual(schema);
107-
});
146+
entry.getField("title");
108147

109-
it("getField group", function () {
110-
const uid = "group.group.group";
111-
const schema = entry.content_type.schema[4].schema[0].schema[0];
112-
const field = entry.getField(uid);
113-
expect(field.uid).toEqual(uid);
114-
expect(field.data_type).toEqual(schema.data_type);
115-
expect(field.schema).toEqual(schema);
148+
expect(fieldInstance).toHaveBeenCalled();
149+
});
116150
});
117151

118152
it("set field data restriction", async () => {

0 commit comments

Comments
 (0)