Skip to content

Commit 5ce5f82

Browse files
committed
WIP: Test GitHub Actions integration test workflow
1 parent bf6fdde commit 5ce5f82

File tree

29 files changed

+2085
-554
lines changed

29 files changed

+2085
-554
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
HUSKY: 0
11+
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: ./.github/actions/setup-node
20+
21+
- name: Cache Docker
22+
uses: satackey/[email protected]
23+
with:
24+
image: specmatic/specmatic:2.21.0
25+
26+
- name: Run integration tests
27+
run: pnpm nx test:integration storyblok-js-client

packages/js-client/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"test:unit:ci": "vitest run",
4848
"test:unit:ui": "vitest --ui",
4949
"test:e2e": "vitest run -c vitest.config.e2e.ts",
50+
"test:integration": "pnpx vitest run -c vitest.config.e2e.ts tests/api/mapi.e2e.ts",
5051
"lint": "eslint .",
5152
"lint:fix": "eslint . --fix",
5253
"playground": "pnpm run --filter ./playground/vanilla dev",
@@ -58,6 +59,8 @@
5859
"devDependencies": {
5960
"@arethetypeswrong/core": "^0.18.2",
6061
"@storyblok/eslint-config": "workspace:*",
62+
"@storyblok/openapi": "workspace:*",
63+
"@storyblok/test-utils": "workspace:*",
6164
"@tsconfig/recommended": "^1.0.8",
6265
"@vitest/coverage-v8": "^3.1.3",
6366
"@vitest/ui": "^3.1.3",

packages/js-client/specmatic.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": 2,
3+
"contracts": [
4+
{
5+
"consumes": [
6+
"./node_modules/@storyblok/openapi/dist/mapi/stories.yaml",
7+
"./node_modules/@storyblok/openapi/dist/mapi/users.yaml"
8+
]
9+
}
10+
]
11+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import StoryblokClient from 'storyblok-js-client';
2+
// TODO
3+
import { describe, expect, it } from '../../../test-utils/src/unit-test/utils';
4+
import { hasStories, makeStory } from '../../../test-utils/src/preconditions/stories';
5+
6+
const makeMapi = ({ baseURL }: { baseURL: string }) => new StoryblokClient({
7+
oauthToken: 'Bearer super-valid-token',
8+
endpoint: `${baseURL}/v1`,
9+
});
10+
11+
describe('getAll()', () => {
12+
it('should return a list of stories', async ({ prepare, stubServer }) => {
13+
const mapi = makeMapi(stubServer);
14+
15+
await prepare(hasStories({ spaceId: '123', stories: [] }));
16+
const resultEmpty = await mapi.getAll(
17+
`spaces/123/stories`,
18+
);
19+
expect(resultEmpty.length).toBe(0);
20+
21+
const story = makeStory({ name: 'foo bar' });
22+
await prepare(hasStories({ spaceId: '123', stories: [story] }));
23+
const result = await mapi.getAll(
24+
`spaces/123/stories`,
25+
);
26+
expect(result[0].name).toBe(story.name);
27+
});
28+
});
29+
30+
// describe('mapi', () => {
31+
32+
// let client: StoryblokClient;
33+
34+
// beforeEach(() => {
35+
// // Setup default mocks
36+
// client = new StoryblokClient({
37+
// accessToken: process.env.VITE_ACCESS_TOKEN,
38+
// cache: { type: 'memory', clear: 'auto' },
39+
// });
40+
// });
41+
// // TODO: Uncomment when we have a valid token
42+
// /* if (process.env.VITE_OAUTH_TOKEN) {
43+
// describe('management API', () => {
44+
// const spaceId = process.env.VITE_SPACE_ID
45+
// describe('should return all spaces', async () => {
46+
// const StoryblokManagement = new StoryblokClient({
47+
// oauthToken: process.env.VITE_OAUTH_TOKEN,
48+
// })
49+
// const result = await StoryblokManagement.getAll(
50+
// `spaces/${spaceId}/stories`
51+
// )
52+
// expect(result.length).toBeGreaterThan(0)
53+
// })
54+
// })
55+
// } */
56+
57+
// describe('get function', () => {
58+
// it('get(\'cdn/spaces/me\') should return the space information', async () => {
59+
// const { data } = await client.get('cdn/spaces/me');
60+
// expect(data.space.id).toBe(Number(process.env.VITE_SPACE_ID));
61+
// });
62+
63+
// it('get(\'cdn/stories\') should return all stories', async () => {
64+
// const { data } = await client.get('cdn/stories');
65+
// expect(data.stories.length).toBeGreaterThan(0);
66+
// });
67+
68+
// it('get(\'cdn/stories/testcontent-0\' should return the specific story', async () => {
69+
// const { data } = await client.get('cdn/stories/testcontent-0');
70+
// expect(data.story.slug).toBe('testcontent-0');
71+
// });
72+
73+
// it('get(\'cdn/stories\' { starts_with: testcontent-0 } should return the specific story', async () => {
74+
// const { data } = await client.get('cdn/stories', {
75+
// starts_with: 'testcontent-0',
76+
// });
77+
// expect(data.stories.length).toBe(1);
78+
// });
79+
80+
// it('get(\'cdn/stories/testcontent-draft\', { version: \'draft\' }) should return the specific story draft', async () => {
81+
// const { data } = await client.get('cdn/stories/testcontent-draft', {
82+
// version: 'draft',
83+
// });
84+
// expect(data.story.slug).toBe('testcontent-draft');
85+
// });
86+
87+
// it('get(\'cdn/stories/testcontent-0\', { version: \'published\' }) should return the specific story published', async () => {
88+
// const { data } = await client.get('cdn/stories/testcontent-0', {
89+
// version: 'published',
90+
// });
91+
// expect(data.story.slug).toBe('testcontent-0');
92+
// });
93+
94+
// it('cdn/stories/testcontent-0 should resolve author relations', async () => {
95+
// const { data } = await client.get('cdn/stories/testcontent-0', {
96+
// resolve_relations: 'root.author',
97+
// });
98+
99+
// expect(data.story.content.author[0].slug).toBe('edgar-allan-poe');
100+
// });
101+
102+
// it('get(\'cdn/stories\', { by_slugs: \'folder/*\' }) should return the specific story', async () => {
103+
// const { data } = await client.get('cdn/stories', {
104+
// by_slugs: 'folder/*',
105+
// });
106+
// expect(data.stories.length).toBeGreaterThan(0);
107+
// });
108+
// });
109+
110+
// describe('getAll function', () => {
111+
// it('getAll(\'cdn/stories\') should return all stories', async () => {
112+
// const result = await client.getAll('cdn/stories', {});
113+
// expect(result.length).toBeGreaterThan(0);
114+
// });
115+
116+
// it('getAll(\'cdn/stories\') should return all stories with filtered results', async () => {
117+
// const result = await client.getAll('cdn/stories', {
118+
// starts_with: 'testcontent-0',
119+
// });
120+
// expect(result.length).toBe(1);
121+
// });
122+
123+
// it('getAll(\'cdn/stories\', filter_query: { __or: [{ category: { any_in_array: \'Category 1\' } }, { category: { any_in_array: \'Category 2\' } }]}) should return all stories with the specific filter applied', async () => {
124+
// const result = await client.getAll('cdn/stories', {
125+
// filter_query: {
126+
// __or: [
127+
// { category: { any_in_array: 'Category 1' } },
128+
// { category: { any_in_array: 'Category 2' } },
129+
// ],
130+
// },
131+
// });
132+
// expect(result.length).toBeGreaterThan(0);
133+
// });
134+
135+
// it('getAll(\'cdn/stories\', {by_slugs: \'folder/*\'}) should return all stories with the specific filter applied', async () => {
136+
// const result = await client.getAll('cdn/stories', {
137+
// by_slugs: 'folder/*',
138+
// });
139+
// expect(result.length).toBeGreaterThan(0);
140+
// });
141+
142+
// it('getAll(\'cdn/links\') should return all links', async () => {
143+
// const result = await client.getAll('cdn/links', {});
144+
// expect(result.length).toBeGreaterThan(0);
145+
// });
146+
// });
147+
148+
// describe('caching', () => {
149+
// it('get(\'cdn/spaces/me\') should not be cached', async () => {
150+
// const provider = client.cacheProvider();
151+
// await provider.flush();
152+
// await client.get('cdn/spaces/me');
153+
// expect(Object.values(provider.getAll()).length).toBe(0);
154+
// });
155+
156+
// it('get(\'cdn/stories\') should be cached when is a published version', async () => {
157+
// const cacheVersion = client.cacheVersion();
158+
159+
// await client.get('cdn/stories');
160+
161+
// expect(cacheVersion).not.toBe(undefined);
162+
163+
// const newCacheVersion = client.cacheVersion();
164+
165+
// await client.get('cdn/stories');
166+
167+
// expect(newCacheVersion).toBe(client.cacheVersion());
168+
169+
// await client.get('cdn/stories');
170+
171+
// expect(newCacheVersion).toBe(client.cacheVersion());
172+
// });
173+
// });
174+
// });

packages/openapi/resources/mapi/assets/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.1.1
1+
openapi: 3.0.0
22
info:
33
title: Storyblok Assets API
44
version: 1.0.0

packages/openapi/resources/mapi/component_folders/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.1.1
1+
openapi: 3.0.0
22
info:
33
title: Storyblok Component Folders API
44
version: 1.0.0

packages/openapi/resources/mapi/components/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.1.1
1+
openapi: 3.0.0
22
info:
33
title: Storyblok Components API
44
version: 1.0.0

packages/openapi/resources/mapi/datasource_entries/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.1.1
1+
openapi: 3.0.0
22
info:
33
title: Storyblok Datasource Entries API
44
version: 1.0.0
@@ -200,4 +200,4 @@ components:
200200
description: The numeric ID of the datasource
201201
dimension_value:
202202
type: string
203-
description: Given value in the requested dimension
203+
description: Given value in the requested dimension

packages/openapi/resources/mapi/datasources/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.1.1
1+
openapi: 3.0.0
22
info:
33
title: Storyblok Datasources API
44
version: 1.0.0
@@ -214,4 +214,4 @@ components:
214214
updated_at:
215215
type: string
216216
format: date-time
217-
description: Latest update date
217+
description: Latest update date

packages/openapi/resources/mapi/internal_tags/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.1.1
1+
openapi: 3.0.0
22
info:
33
title: Storyblok Internal Tags API
44
version: 1.0.0

0 commit comments

Comments
 (0)