Skip to content

Commit 925d0a3

Browse files
committed
WIP: Test GitHub Actions integration test workflow
1 parent bf6fdde commit 925d0a3

File tree

33 files changed

+2645
-555
lines changed

33 files changed

+2645
-555
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Integration Tests
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- "!**"
8+
branches:
9+
- "**"
10+
pull_request:
11+
12+
env:
13+
HUSKY: 0
14+
NX_REJECT_UNKNOWN_LOCAL_CACHE: 0
15+
16+
jobs:
17+
prepare-docker:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Set up Docker cache
21+
id: cache-docker-image
22+
uses: actions/cache@v4
23+
with:
24+
path: /tmp/specmatic.tar
25+
key: ${{ runner.os }}-docker-specmatic-2.21.0
26+
27+
- name: Pull and save Docker image to cache
28+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
29+
run: |
30+
echo "Cache miss. Pulling image and saving to cache..."
31+
docker pull specmatic/specmatic:2.21.0
32+
docker save specmatic/specmatic:2.21.0 --output /tmp/specmatic.tar
33+
34+
integration-test:
35+
runs-on: ubuntu-latest
36+
needs: [prepare-docker]
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- uses: ./.github/actions/setup-node
41+
42+
- name: Restore Docker image from cache
43+
uses: actions/cache@v4
44+
with:
45+
path: /tmp/specmatic.tar
46+
key: ${{ runner.os }}-docker-specmatic-2.21.0
47+
48+
- name: Load Docker image
49+
run: docker load --input /tmp/specmatic.tar
50+
51+
- name: Build
52+
run: pnpm nx run-many --target=build --parallel=3 -p="tag:npm:public"
53+
54+
- name: Run integration tests
55+
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 tests/api/mapi2.e2e.ts tests/api/mapi3.e2e.ts tests/api/mapi4.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: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
for (let i = 0; i < 100; i++) {
13+
it(`${i}: should return a list of stories`, async ({ prepare, stubServer }) => {
14+
const mapi = makeMapi(stubServer);
15+
16+
await prepare(hasStories({ spaceId: '123', stories: [] }));
17+
const resultEmpty = await mapi.getAll(
18+
`spaces/123/stories`,
19+
);
20+
expect(resultEmpty.length).toBe(0);
21+
22+
const story = makeStory({ name: 'foo bar' });
23+
await prepare(hasStories({ spaceId: '123', stories: [makeStory({ name: 'foo bar' })] }));
24+
const result = await mapi.getAll(
25+
`spaces/123/stories`,
26+
);
27+
expect(result[0].name).toBe(story.name);
28+
});
29+
}
30+
});
31+
32+
// describe('mapi', () => {
33+
34+
// let client: StoryblokClient;
35+
36+
// beforeEach(() => {
37+
// // Setup default mocks
38+
// client = new StoryblokClient({
39+
// accessToken: process.env.VITE_ACCESS_TOKEN,
40+
// cache: { type: 'memory', clear: 'auto' },
41+
// });
42+
// });
43+
// // TODO: Uncomment when we have a valid token
44+
// /* if (process.env.VITE_OAUTH_TOKEN) {
45+
// describe('management API', () => {
46+
// const spaceId = process.env.VITE_SPACE_ID
47+
// describe('should return all spaces', async () => {
48+
// const StoryblokManagement = new StoryblokClient({
49+
// oauthToken: process.env.VITE_OAUTH_TOKEN,
50+
// })
51+
// const result = await StoryblokManagement.getAll(
52+
// `spaces/${spaceId}/stories`
53+
// )
54+
// expect(result.length).toBeGreaterThan(0)
55+
// })
56+
// })
57+
// } */
58+
59+
// describe('get function', () => {
60+
// it('get(\'cdn/spaces/me\') should return the space information', async () => {
61+
// const { data } = await client.get('cdn/spaces/me');
62+
// expect(data.space.id).toBe(Number(process.env.VITE_SPACE_ID));
63+
// });
64+
65+
// it('get(\'cdn/stories\') should return all stories', async () => {
66+
// const { data } = await client.get('cdn/stories');
67+
// expect(data.stories.length).toBeGreaterThan(0);
68+
// });
69+
70+
// it('get(\'cdn/stories/testcontent-0\' should return the specific story', async () => {
71+
// const { data } = await client.get('cdn/stories/testcontent-0');
72+
// expect(data.story.slug).toBe('testcontent-0');
73+
// });
74+
75+
// it('get(\'cdn/stories\' { starts_with: testcontent-0 } should return the specific story', async () => {
76+
// const { data } = await client.get('cdn/stories', {
77+
// starts_with: 'testcontent-0',
78+
// });
79+
// expect(data.stories.length).toBe(1);
80+
// });
81+
82+
// it('get(\'cdn/stories/testcontent-draft\', { version: \'draft\' }) should return the specific story draft', async () => {
83+
// const { data } = await client.get('cdn/stories/testcontent-draft', {
84+
// version: 'draft',
85+
// });
86+
// expect(data.story.slug).toBe('testcontent-draft');
87+
// });
88+
89+
// it('get(\'cdn/stories/testcontent-0\', { version: \'published\' }) should return the specific story published', async () => {
90+
// const { data } = await client.get('cdn/stories/testcontent-0', {
91+
// version: 'published',
92+
// });
93+
// expect(data.story.slug).toBe('testcontent-0');
94+
// });
95+
96+
// it('cdn/stories/testcontent-0 should resolve author relations', async () => {
97+
// const { data } = await client.get('cdn/stories/testcontent-0', {
98+
// resolve_relations: 'root.author',
99+
// });
100+
101+
// expect(data.story.content.author[0].slug).toBe('edgar-allan-poe');
102+
// });
103+
104+
// it('get(\'cdn/stories\', { by_slugs: \'folder/*\' }) should return the specific story', async () => {
105+
// const { data } = await client.get('cdn/stories', {
106+
// by_slugs: 'folder/*',
107+
// });
108+
// expect(data.stories.length).toBeGreaterThan(0);
109+
// });
110+
// });
111+
112+
// describe('getAll function', () => {
113+
// it('getAll(\'cdn/stories\') should return all stories', async () => {
114+
// const result = await client.getAll('cdn/stories', {});
115+
// expect(result.length).toBeGreaterThan(0);
116+
// });
117+
118+
// it('getAll(\'cdn/stories\') should return all stories with filtered results', async () => {
119+
// const result = await client.getAll('cdn/stories', {
120+
// starts_with: 'testcontent-0',
121+
// });
122+
// expect(result.length).toBe(1);
123+
// });
124+
125+
// 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 () => {
126+
// const result = await client.getAll('cdn/stories', {
127+
// filter_query: {
128+
// __or: [
129+
// { category: { any_in_array: 'Category 1' } },
130+
// { category: { any_in_array: 'Category 2' } },
131+
// ],
132+
// },
133+
// });
134+
// expect(result.length).toBeGreaterThan(0);
135+
// });
136+
137+
// it('getAll(\'cdn/stories\', {by_slugs: \'folder/*\'}) should return all stories with the specific filter applied', async () => {
138+
// const result = await client.getAll('cdn/stories', {
139+
// by_slugs: 'folder/*',
140+
// });
141+
// expect(result.length).toBeGreaterThan(0);
142+
// });
143+
144+
// it('getAll(\'cdn/links\') should return all links', async () => {
145+
// const result = await client.getAll('cdn/links', {});
146+
// expect(result.length).toBeGreaterThan(0);
147+
// });
148+
// });
149+
150+
// describe('caching', () => {
151+
// it('get(\'cdn/spaces/me\') should not be cached', async () => {
152+
// const provider = client.cacheProvider();
153+
// await provider.flush();
154+
// await client.get('cdn/spaces/me');
155+
// expect(Object.values(provider.getAll()).length).toBe(0);
156+
// });
157+
158+
// it('get(\'cdn/stories\') should be cached when is a published version', async () => {
159+
// const cacheVersion = client.cacheVersion();
160+
161+
// await client.get('cdn/stories');
162+
163+
// expect(cacheVersion).not.toBe(undefined);
164+
165+
// const newCacheVersion = client.cacheVersion();
166+
167+
// await client.get('cdn/stories');
168+
169+
// expect(newCacheVersion).toBe(client.cacheVersion());
170+
171+
// await client.get('cdn/stories');
172+
173+
// expect(newCacheVersion).toBe(client.cacheVersion());
174+
// });
175+
// });
176+
// });

0 commit comments

Comments
 (0)