@uidu/client 3.9.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/declarations/src/actions.d.ts +12 -0
- package/dist/declarations/src/client.d.ts +15 -0
- package/dist/declarations/src/generated/index.d.ts +11925 -22
- package/dist/declarations/src/index.d.ts +6 -1
- package/dist/declarations/src/models.d.ts +326 -0
- package/dist/declarations/src/sites.d.ts +81 -0
- package/dist/declarations/src/types.d.ts +8 -1
- package/dist/uidu-client.cjs.dev.js +398 -2
- package/dist/uidu-client.cjs.prod.js +398 -2
- package/dist/uidu-client.esm.js +373 -3
- package/package.json +1 -1
- package/src/actions.ts +19 -0
- package/src/client.test.ts +56 -0
- package/src/client.ts +47 -4
- package/src/generated/index.ts +4104 -22
- package/src/index.ts +48 -1
- package/src/models.test.ts +245 -0
- package/src/models.ts +328 -0
- package/src/queries/actions/ExecuteAction.graphql +10 -0
- package/src/queries/models/ModelFields.graphql +39 -0
- package/src/queries/models/ModelMutations.graphql +173 -0
- package/src/queries/models/ModelQueries.graphql +44 -0
- package/src/queries/sites/SiteFields.graphql +51 -0
- package/src/queries/sites/SiteQueries.graphql +53 -0
- package/src/sites.test.ts +315 -0
- package/src/sites.ts +173 -0
- package/src/types.ts +8 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# The mutations a custom app session token may call (CustomApps::Scope in the
|
|
2
|
+
# uidu repo). Schema writes (models, fields, options) are interim: step 3 of
|
|
3
|
+
# the custom apps spec moves them to an install-time manifest.
|
|
4
|
+
|
|
5
|
+
mutation CreateModel($input: CreateModelInput!) {
|
|
6
|
+
createModel(input: $input) {
|
|
7
|
+
model {
|
|
8
|
+
...ModelSchema
|
|
9
|
+
}
|
|
10
|
+
errors {
|
|
11
|
+
key
|
|
12
|
+
name
|
|
13
|
+
type
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
mutation UpdateModel($input: UpdateModelInput!) {
|
|
19
|
+
updateModel(input: $input) {
|
|
20
|
+
model {
|
|
21
|
+
...ModelSchema
|
|
22
|
+
}
|
|
23
|
+
errors {
|
|
24
|
+
key
|
|
25
|
+
name
|
|
26
|
+
type
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
mutation CreateField($input: CreateFieldInput!) {
|
|
32
|
+
createField(input: $input) {
|
|
33
|
+
field {
|
|
34
|
+
...ModelField
|
|
35
|
+
}
|
|
36
|
+
errors {
|
|
37
|
+
key
|
|
38
|
+
name
|
|
39
|
+
type
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
mutation UpdateField($input: UpdateFieldInput!) {
|
|
45
|
+
updateField(input: $input) {
|
|
46
|
+
field {
|
|
47
|
+
...ModelField
|
|
48
|
+
}
|
|
49
|
+
errors {
|
|
50
|
+
key
|
|
51
|
+
name
|
|
52
|
+
type
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
mutation DeleteField($input: DeleteFieldInput!) {
|
|
58
|
+
deleteField(input: $input) {
|
|
59
|
+
field {
|
|
60
|
+
id
|
|
61
|
+
}
|
|
62
|
+
errors {
|
|
63
|
+
key
|
|
64
|
+
name
|
|
65
|
+
type
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
mutation CreateFieldOption($input: CreateFieldOptionInput!) {
|
|
71
|
+
createFieldOption(input: $input) {
|
|
72
|
+
fieldOption {
|
|
73
|
+
...ModelFieldOption
|
|
74
|
+
}
|
|
75
|
+
errors {
|
|
76
|
+
key
|
|
77
|
+
name
|
|
78
|
+
type
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
mutation UpdateFieldOption($input: UpdateFieldOptionInput!) {
|
|
84
|
+
updateFieldOption(input: $input) {
|
|
85
|
+
fieldOption {
|
|
86
|
+
...ModelFieldOption
|
|
87
|
+
}
|
|
88
|
+
errors {
|
|
89
|
+
key
|
|
90
|
+
name
|
|
91
|
+
type
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
mutation DeleteFieldOption($input: DeleteFieldOptionInput!) {
|
|
97
|
+
deleteFieldOption(input: $input) {
|
|
98
|
+
fieldOption {
|
|
99
|
+
id
|
|
100
|
+
}
|
|
101
|
+
errors {
|
|
102
|
+
key
|
|
103
|
+
name
|
|
104
|
+
type
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
mutation CreateModelItem($input: CreateModelItemInput!) {
|
|
110
|
+
createModelItem(input: $input) {
|
|
111
|
+
modelItem {
|
|
112
|
+
...ModelItemFields
|
|
113
|
+
}
|
|
114
|
+
errors {
|
|
115
|
+
key
|
|
116
|
+
name
|
|
117
|
+
type
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
mutation UpdateModelItem($input: UpdateModelItemInput!) {
|
|
123
|
+
updateModelItem(input: $input) {
|
|
124
|
+
modelItem {
|
|
125
|
+
...ModelItemFields
|
|
126
|
+
}
|
|
127
|
+
errors {
|
|
128
|
+
key
|
|
129
|
+
name
|
|
130
|
+
type
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
mutation DeleteModelItem($input: DeleteModelItemInput!) {
|
|
136
|
+
deleteModelItem(input: $input) {
|
|
137
|
+
modelItem {
|
|
138
|
+
id
|
|
139
|
+
}
|
|
140
|
+
errors {
|
|
141
|
+
key
|
|
142
|
+
name
|
|
143
|
+
type
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
mutation UpdateFieldValue($input: UpdateFieldValueInput!) {
|
|
149
|
+
updateFieldValue(input: $input) {
|
|
150
|
+
fieldValue {
|
|
151
|
+
id
|
|
152
|
+
content
|
|
153
|
+
}
|
|
154
|
+
errors {
|
|
155
|
+
key
|
|
156
|
+
name
|
|
157
|
+
type
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
mutation DeleteFieldValue($input: DeleteFieldValueInput!) {
|
|
163
|
+
deleteFieldValue(input: $input) {
|
|
164
|
+
fieldValue {
|
|
165
|
+
id
|
|
166
|
+
}
|
|
167
|
+
errors {
|
|
168
|
+
key
|
|
169
|
+
name
|
|
170
|
+
type
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
query ListAppModels($workspaceAppId: ID!) {
|
|
2
|
+
node(id: $workspaceAppId) {
|
|
3
|
+
__typename
|
|
4
|
+
... on WorkspaceApp {
|
|
5
|
+
id
|
|
6
|
+
modelList {
|
|
7
|
+
...ModelSchema
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
query GetModel($id: ID!) {
|
|
14
|
+
node(id: $id) {
|
|
15
|
+
__typename
|
|
16
|
+
... on Model {
|
|
17
|
+
...ModelSchema
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
query ListModelItems($modelId: ID!, $params: SearchParams) {
|
|
23
|
+
node(id: $modelId) {
|
|
24
|
+
__typename
|
|
25
|
+
... on Model {
|
|
26
|
+
id
|
|
27
|
+
modelItemList(params: $params) {
|
|
28
|
+
...ModelItemFields
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
query GetModelItem($id: ID!) {
|
|
35
|
+
node(id: $id) {
|
|
36
|
+
__typename
|
|
37
|
+
... on ModelItem {
|
|
38
|
+
...ModelItemFields
|
|
39
|
+
model {
|
|
40
|
+
id
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# The new CMS substrate: a Site owns page-kind Models (page types), whose
|
|
2
|
+
# ModelItems are pages; each page's `blocks` are block-kind ModelItems placed
|
|
3
|
+
# in order. Distinct from the legacy `currentWorkspace.project(id:)` path read
|
|
4
|
+
# by `cms.ts`, which stays as it is.
|
|
5
|
+
|
|
6
|
+
fragment SiteFields on Site {
|
|
7
|
+
id
|
|
8
|
+
name
|
|
9
|
+
shortname
|
|
10
|
+
domain
|
|
11
|
+
preferences
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
fragment SiteModelFields on Model {
|
|
15
|
+
id
|
|
16
|
+
name
|
|
17
|
+
kind
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fragment SitePageMeta on ModelItem {
|
|
21
|
+
id
|
|
22
|
+
name
|
|
23
|
+
slug
|
|
24
|
+
publishedAt
|
|
25
|
+
publishableStatus
|
|
26
|
+
model {
|
|
27
|
+
...SiteModelFields
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fragment SiteBlockItem on ModelItem {
|
|
32
|
+
id
|
|
33
|
+
name
|
|
34
|
+
fieldValuesByShortname
|
|
35
|
+
model {
|
|
36
|
+
...SiteModelFields
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fragment SitePageContent on ModelItem {
|
|
41
|
+
...SitePageMeta
|
|
42
|
+
fieldValuesByShortname
|
|
43
|
+
blocks {
|
|
44
|
+
id
|
|
45
|
+
position
|
|
46
|
+
fieldValueId
|
|
47
|
+
modelItem {
|
|
48
|
+
...SiteBlockItem
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# `siteByDomain` and `node(id:)` are both public: they resolve with a
|
|
2
|
+
# `publicToken` or no credentials at all.
|
|
3
|
+
|
|
4
|
+
query GetSiteByDomain($domain: String!) {
|
|
5
|
+
siteByDomain(domain: $domain) {
|
|
6
|
+
...SiteFields
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
query GetSite($id: ID!) {
|
|
11
|
+
node(id: $id) {
|
|
12
|
+
__typename
|
|
13
|
+
... on Site {
|
|
14
|
+
...SiteFields
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
query GetSitePageBySlug($siteId: ID!, $slug: String!, $includeDrafts: Boolean) {
|
|
20
|
+
node(id: $siteId) {
|
|
21
|
+
__typename
|
|
22
|
+
... on Site {
|
|
23
|
+
id
|
|
24
|
+
pageBySlug(slug: $slug, includeDrafts: $includeDrafts) {
|
|
25
|
+
...SitePageContent
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
query ListSitePages($siteId: ID!) {
|
|
32
|
+
node(id: $siteId) {
|
|
33
|
+
__typename
|
|
34
|
+
... on Site {
|
|
35
|
+
id
|
|
36
|
+
pages {
|
|
37
|
+
...SitePageMeta
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
query GetSiteSingletonBlock($siteId: ID!, $shortname: String!) {
|
|
44
|
+
node(id: $siteId) {
|
|
45
|
+
__typename
|
|
46
|
+
... on Site {
|
|
47
|
+
id
|
|
48
|
+
singletonBlock(shortname: $shortname) {
|
|
49
|
+
...SitePageContent
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const request = vi.fn();
|
|
4
|
+
|
|
5
|
+
vi.mock('graphql-request', () => ({
|
|
6
|
+
GraphQLClient: class {
|
|
7
|
+
request = request;
|
|
8
|
+
},
|
|
9
|
+
ClientError: class extends Error {},
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const { createClient } = await import('./client');
|
|
13
|
+
const sites = await import('./sites');
|
|
14
|
+
|
|
15
|
+
const client = createClient({ workspace: 'acme', publicToken: 'pub' });
|
|
16
|
+
|
|
17
|
+
const operation = (call: unknown[]) =>
|
|
18
|
+
(call[0] as { definitions: Array<{ name?: { value: string } }> })
|
|
19
|
+
.definitions[0].name?.value;
|
|
20
|
+
|
|
21
|
+
const site = {
|
|
22
|
+
id: 'site_1',
|
|
23
|
+
name: 'Acme',
|
|
24
|
+
shortname: 'acme',
|
|
25
|
+
domain: 'www.acme.org',
|
|
26
|
+
preferences: null,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const pageType = { id: 'mdl_page', name: 'Page', kind: 'page' };
|
|
30
|
+
const hero = { id: 'mdl_hero', name: 'Hero', kind: 'block' };
|
|
31
|
+
const faq = { id: 'mdl_faq', name: 'FAQ', kind: 'block' };
|
|
32
|
+
|
|
33
|
+
const meta = (overrides: Record<string, unknown> = {}) => ({
|
|
34
|
+
id: 'itm_home',
|
|
35
|
+
name: 'Home',
|
|
36
|
+
slug: 'home',
|
|
37
|
+
publishedAt: '2026-09-01T00:00:00Z',
|
|
38
|
+
publishableStatus: 'Published',
|
|
39
|
+
model: pageType,
|
|
40
|
+
...overrides,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const placement = (
|
|
44
|
+
position: number,
|
|
45
|
+
model: typeof hero,
|
|
46
|
+
fieldValuesByShortname: Record<string, unknown>,
|
|
47
|
+
) => ({
|
|
48
|
+
id: `plc_${position}`,
|
|
49
|
+
position,
|
|
50
|
+
fieldValueId: `fv_${position}`,
|
|
51
|
+
modelItem: {
|
|
52
|
+
id: `itm_block_${position}`,
|
|
53
|
+
name: model.name,
|
|
54
|
+
model,
|
|
55
|
+
fieldValuesByShortname,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
beforeEach(() => request.mockReset());
|
|
60
|
+
|
|
61
|
+
describe('getSiteByDomain', () => {
|
|
62
|
+
it('reads siteByDomain with the public token', async () => {
|
|
63
|
+
request.mockResolvedValue({ siteByDomain: site });
|
|
64
|
+
await expect(
|
|
65
|
+
sites.getSiteByDomain(client, { domain: 'www.acme.org' }),
|
|
66
|
+
).resolves.toEqual(site);
|
|
67
|
+
expect(operation(request.mock.calls[0])).toBe('GetSiteByDomain');
|
|
68
|
+
expect(request.mock.calls[0][1]).toEqual({ domain: 'www.acme.org' });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('returns null for an unknown domain', async () => {
|
|
72
|
+
request.mockResolvedValue({ siteByDomain: null });
|
|
73
|
+
await expect(
|
|
74
|
+
sites.getSiteByDomain(client, { domain: 'nope.org' }),
|
|
75
|
+
).resolves.toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('getSite', () => {
|
|
80
|
+
it('reads the Site through node(id:)', async () => {
|
|
81
|
+
request.mockResolvedValue({ node: { __typename: 'Site', ...site } });
|
|
82
|
+
await expect(sites.getSite(client, { id: 'site_1' })).resolves.toEqual({
|
|
83
|
+
__typename: 'Site',
|
|
84
|
+
...site,
|
|
85
|
+
});
|
|
86
|
+
expect(operation(request.mock.calls[0])).toBe('GetSite');
|
|
87
|
+
expect(request.mock.calls[0][1]).toEqual({ id: 'site_1' });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns null when the node is not a Site', async () => {
|
|
91
|
+
request.mockResolvedValue({ node: { __typename: 'Page' } });
|
|
92
|
+
await expect(sites.getSite(client, { id: 'x' })).resolves.toBeNull();
|
|
93
|
+
request.mockResolvedValue({ node: null });
|
|
94
|
+
await expect(sites.getSite(client, { id: 'x' })).resolves.toBeNull();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('getPageBySlug', () => {
|
|
99
|
+
it('maps the page, its fields and its blocks in position order', async () => {
|
|
100
|
+
request.mockResolvedValue({
|
|
101
|
+
node: {
|
|
102
|
+
__typename: 'Site',
|
|
103
|
+
id: 'site_1',
|
|
104
|
+
pageBySlug: {
|
|
105
|
+
...meta(),
|
|
106
|
+
fieldValuesByShortname: { title: 'Welcome' },
|
|
107
|
+
blocks: [
|
|
108
|
+
placement(2, faq, { question: 'Why?' }),
|
|
109
|
+
placement(1, hero, { headline: 'Hi' }),
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const page = await sites.getPageBySlug(client, {
|
|
116
|
+
siteId: 'site_1',
|
|
117
|
+
slug: 'home',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(operation(request.mock.calls[0])).toBe('GetSitePageBySlug');
|
|
121
|
+
expect(request.mock.calls[0][1]).toEqual({
|
|
122
|
+
siteId: 'site_1',
|
|
123
|
+
slug: 'home',
|
|
124
|
+
});
|
|
125
|
+
expect(page).toEqual({
|
|
126
|
+
id: 'itm_home',
|
|
127
|
+
name: 'Home',
|
|
128
|
+
slug: 'home',
|
|
129
|
+
publishedAt: '2026-09-01T00:00:00Z',
|
|
130
|
+
status: 'Published',
|
|
131
|
+
model: pageType,
|
|
132
|
+
fields: { title: 'Welcome' },
|
|
133
|
+
blocks: [
|
|
134
|
+
{
|
|
135
|
+
id: 'itm_block_1',
|
|
136
|
+
name: 'Hero',
|
|
137
|
+
model: hero,
|
|
138
|
+
fields: { headline: 'Hi' },
|
|
139
|
+
position: 1,
|
|
140
|
+
placementId: 'fv_1',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: 'itm_block_2',
|
|
144
|
+
name: 'FAQ',
|
|
145
|
+
model: faq,
|
|
146
|
+
fields: { question: 'Why?' },
|
|
147
|
+
position: 2,
|
|
148
|
+
placementId: 'fv_2',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('passes includeDrafts through', async () => {
|
|
155
|
+
request.mockResolvedValue({
|
|
156
|
+
node: { __typename: 'Site', pageBySlug: null },
|
|
157
|
+
});
|
|
158
|
+
await sites.getPageBySlug(client, {
|
|
159
|
+
siteId: 'site_1',
|
|
160
|
+
slug: 'draft',
|
|
161
|
+
includeDrafts: true,
|
|
162
|
+
});
|
|
163
|
+
expect(request.mock.calls[0][1]).toEqual({
|
|
164
|
+
siteId: 'site_1',
|
|
165
|
+
slug: 'draft',
|
|
166
|
+
includeDrafts: true,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('returns null for a missing page or a non-Site node', async () => {
|
|
171
|
+
request.mockResolvedValue({
|
|
172
|
+
node: { __typename: 'Site', pageBySlug: null },
|
|
173
|
+
});
|
|
174
|
+
await expect(
|
|
175
|
+
sites.getPageBySlug(client, { siteId: 'site_1', slug: 'x' }),
|
|
176
|
+
).resolves.toBeNull();
|
|
177
|
+
request.mockResolvedValue({ node: null });
|
|
178
|
+
await expect(
|
|
179
|
+
sites.getPageBySlug(client, { siteId: 'x', slug: 'x' }),
|
|
180
|
+
).resolves.toBeNull();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('defaults missing field values to an empty map', async () => {
|
|
184
|
+
request.mockResolvedValue({
|
|
185
|
+
node: {
|
|
186
|
+
__typename: 'Site',
|
|
187
|
+
pageBySlug: {
|
|
188
|
+
...meta(),
|
|
189
|
+
fieldValuesByShortname: null,
|
|
190
|
+
blocks: [placement(1, hero, null as never)],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
const page = await sites.getPageBySlug(client, {
|
|
195
|
+
siteId: 'site_1',
|
|
196
|
+
slug: 'home',
|
|
197
|
+
});
|
|
198
|
+
expect(page?.fields).toEqual({});
|
|
199
|
+
expect(page?.blocks[0].fields).toEqual({});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('listSitePages', () => {
|
|
204
|
+
const blogPost = { id: 'mdl_post', name: 'Blog post', kind: 'page' };
|
|
205
|
+
const header = { id: 'mdl_header', name: 'Header', kind: 'singleton' };
|
|
206
|
+
const pages = [
|
|
207
|
+
meta(),
|
|
208
|
+
meta({ id: 'itm_post', slug: 'hello', model: blogPost }),
|
|
209
|
+
meta({
|
|
210
|
+
id: 'itm_draft',
|
|
211
|
+
slug: 'wip',
|
|
212
|
+
publishedAt: null,
|
|
213
|
+
publishableStatus: 'Draft',
|
|
214
|
+
}),
|
|
215
|
+
meta({
|
|
216
|
+
id: 'itm_later',
|
|
217
|
+
slug: 'later',
|
|
218
|
+
publishedAt: '2027-01-01T00:00:00Z',
|
|
219
|
+
publishableStatus: 'Scheduled',
|
|
220
|
+
}),
|
|
221
|
+
meta({ id: 'itm_header', slug: null, model: header }),
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
beforeEach(() =>
|
|
225
|
+
request.mockResolvedValue({
|
|
226
|
+
node: { __typename: 'Site', id: 'site_1', pages },
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
it('returns published pages only, without singletons', async () => {
|
|
231
|
+
const result = await sites.listSitePages(client, { siteId: 'site_1' });
|
|
232
|
+
expect(operation(request.mock.calls[0])).toBe('ListSitePages');
|
|
233
|
+
expect(request.mock.calls[0][1]).toEqual({ siteId: 'site_1' });
|
|
234
|
+
expect(result.map((p) => p.id)).toEqual(['itm_home', 'itm_post']);
|
|
235
|
+
expect(result[0]).toEqual({
|
|
236
|
+
id: 'itm_home',
|
|
237
|
+
name: 'Home',
|
|
238
|
+
slug: 'home',
|
|
239
|
+
publishedAt: '2026-09-01T00:00:00Z',
|
|
240
|
+
status: 'Published',
|
|
241
|
+
model: pageType,
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('includes drafts and scheduled pages on request', async () => {
|
|
246
|
+
const result = await sites.listSitePages(client, {
|
|
247
|
+
siteId: 'site_1',
|
|
248
|
+
includeDrafts: true,
|
|
249
|
+
});
|
|
250
|
+
expect(result.map((p) => p.id)).toEqual([
|
|
251
|
+
'itm_home',
|
|
252
|
+
'itm_post',
|
|
253
|
+
'itm_draft',
|
|
254
|
+
'itm_later',
|
|
255
|
+
]);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('filters by page type id or name', async () => {
|
|
259
|
+
for (const pageTypeKey of ['mdl_post', 'Blog post']) {
|
|
260
|
+
const result = await sites.listSitePages(client, {
|
|
261
|
+
siteId: 'site_1',
|
|
262
|
+
pageType: pageTypeKey,
|
|
263
|
+
});
|
|
264
|
+
expect(result.map((p) => p.id)).toEqual(['itm_post']);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('returns an empty list when the node is not a Site', async () => {
|
|
269
|
+
request.mockResolvedValue({ node: null });
|
|
270
|
+
await expect(sites.listSitePages(client, { siteId: 'x' })).resolves.toEqual(
|
|
271
|
+
[],
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe('getSingletonBlock', () => {
|
|
277
|
+
it('reads the singleton by shortname and maps it like a page', async () => {
|
|
278
|
+
const header = { id: 'mdl_header', name: 'Header', kind: 'singleton' };
|
|
279
|
+
request.mockResolvedValue({
|
|
280
|
+
node: {
|
|
281
|
+
__typename: 'Site',
|
|
282
|
+
id: 'site_1',
|
|
283
|
+
singletonBlock: {
|
|
284
|
+
...meta({ id: 'itm_header', slug: null, model: header }),
|
|
285
|
+
fieldValuesByShortname: { logo: 'acme.svg' },
|
|
286
|
+
blocks: [],
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
const block = await sites.getSingletonBlock(client, {
|
|
291
|
+
siteId: 'site_1',
|
|
292
|
+
shortname: 'header',
|
|
293
|
+
});
|
|
294
|
+
expect(operation(request.mock.calls[0])).toBe('GetSiteSingletonBlock');
|
|
295
|
+
expect(request.mock.calls[0][1]).toEqual({
|
|
296
|
+
siteId: 'site_1',
|
|
297
|
+
shortname: 'header',
|
|
298
|
+
});
|
|
299
|
+
expect(block).toMatchObject({
|
|
300
|
+
id: 'itm_header',
|
|
301
|
+
model: header,
|
|
302
|
+
fields: { logo: 'acme.svg' },
|
|
303
|
+
blocks: [],
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('returns null when the Site has no such singleton', async () => {
|
|
308
|
+
request.mockResolvedValue({
|
|
309
|
+
node: { __typename: 'Site', singletonBlock: null },
|
|
310
|
+
});
|
|
311
|
+
await expect(
|
|
312
|
+
sites.getSingletonBlock(client, { siteId: 'site_1', shortname: 'nav' }),
|
|
313
|
+
).resolves.toBeNull();
|
|
314
|
+
});
|
|
315
|
+
});
|