Skip to content

Commit e237498

Browse files
Improve tests
1 parent 9c2085e commit e237498

File tree

5 files changed

+114
-3
lines changed

5 files changed

+114
-3
lines changed

tests/assets.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getClient, guid } from "./_utils";
66
describe("Assets", () => {
77
const { client } = getClient();
88

9-
it("upload and fetch asset", async () => {
9+
it("should upload and fetch asset", async () => {
1010
const fileStream = fs.createReadStream('tests/assets/logo-wide.png');
1111
const fileInfo = fs.statSync('tests/assets/logo-wide.png');
1212

@@ -19,7 +19,7 @@ describe("Assets", () => {
1919
expect(asset.mimeType).toEqual('image/png');
2020
});
2121

22-
it("upload and download asset", async () => {
22+
it("should upload and download asset", async () => {
2323
const fileStream = fs.createReadStream('tests/assets/logo-wide.png');
2424
const fileInfo = fs.statSync('tests/assets/logo-wide.png');
2525

tests/contents.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { SchemaDto } from "../src/api";
2+
import { getClient, guid } from "./_utils";
3+
4+
const { client } = getClient();
5+
6+
let createdSchema: SchemaDto;
7+
8+
beforeAll(async () => {
9+
createdSchema = await client.schemas.postSchema({
10+
name: `schema-${guid()}`,
11+
fields: [{
12+
name: 'field1',
13+
properties: {
14+
fieldType: 'String',
15+
},
16+
}],
17+
isPublished: true,
18+
});
19+
});
20+
21+
describe("Contents", () => {
22+
it("should create and fetch content", async () => {
23+
const value = guid();
24+
25+
const createdContent = await client.contents.postContent(createdSchema.name, {
26+
body: {
27+
field1: {
28+
iv: value
29+
}
30+
},
31+
publish: true
32+
});
33+
34+
const content = await client.contents.getContent(createdSchema.name, createdContent.id);
35+
expect(content.data).toEqual({ field1: { iv: value } });
36+
expect(content.lastModified).toBeDefined();
37+
expect(content.lastModifiedBy).toBeDefined();
38+
expect(content.status).toEqual('Published');
39+
});
40+
41+
it("should create and fetch unpublished content", async () => {
42+
const value = guid();
43+
44+
const createdContent = await client.contents.postContent(createdSchema.name, {
45+
body: {
46+
field1: {
47+
iv: value
48+
}
49+
}
50+
});
51+
52+
const content = await client.contents.getContent(createdSchema.name, createdContent.id, { unpublished: true });
53+
expect(content.data).toEqual({ field1: { iv: value } });
54+
expect(content.lastModified).toBeDefined();
55+
expect(content.lastModifiedBy).toBeDefined();
56+
expect(content.status).toEqual('Draft');
57+
});
58+
})

tests/rules.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getClient, guid } from "./_utils";
2+
3+
const { client } = getClient();
4+
5+
describe("Rules", () => {
6+
it("should create and fetch rule", async () => {
7+
const createdRule = await client.rules.postRule({
8+
action: {
9+
actionType: 'Webhook',
10+
method: 'POST',
11+
payload: 'payload',
12+
payloadType: 'text/plain',
13+
url: 'https://squidex.io'
14+
},
15+
trigger: {
16+
triggerType: 'Manual'
17+
},
18+
});
19+
20+
const rules = await client.rules.getRules();
21+
const rule = rules.items.find(x => x.id === createdRule.id);
22+
expect(rule?.name).toEqual(createdRule.name);
23+
expect(rule?.action).toBeDefined();
24+
expect(rule?.action.actionType).toEqual('Webhook');
25+
expect(rule?.trigger).toBeDefined();
26+
expect(rule?.trigger.triggerType).toEqual('Manual');
27+
});
28+
})

tests/schemas.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { getClient, guid } from "./_utils";
2+
3+
const { client } = getClient();
4+
5+
describe("Schemas", () => {
6+
it("should create and fetch schema", async () => {
7+
const createdSchema = await client.schemas.postSchema({
8+
name: `schema-${guid()}`,
9+
fields: [{
10+
name: 'field1',
11+
properties: {
12+
fieldType: 'String',
13+
},
14+
}],
15+
isPublished: true,
16+
});
17+
18+
const schema = await client.schemas.getSchema(createdSchema.id);
19+
expect(schema.name).toEqual(createdSchema.name);
20+
expect(schema.fields.length).toEqual(1);
21+
expect(schema.fields[0].properties.fieldType).toEqual('String');
22+
expect(schema.type).toBe('Default');
23+
expect(schema.isPublished).toBeTruthy();
24+
});
25+
})

tests/userManagement.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getClient, guid } from "./_utils";
33
describe("User management", () => {
44
const { client } = getClient();
55

6-
it("create user and load user", async () => {
6+
it("should create and fetch user", async () => {
77
const email = `user${guid()}@email.com`;
88

99
const createdUser = await client.userManagement.postUser({

0 commit comments

Comments
 (0)