@jungvonmatt/contentful-fakes 4.1.2 → 5.0.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/dist/cli.js +0 -0
- package/package.json +28 -29
- package/src/index.test.ts +70 -0
- package/src/lib/faker.test.ts +6 -6
package/dist/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-fakes",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Create fake data based on contentful data models",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"contentful",
|
|
7
|
+
"data",
|
|
8
|
+
"fake"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/jungvonmatt/contentful-ssg#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/jungvonmatt/contentful-ssg/issues"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Ben Zörb",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/jungvonmatt/contentful-ssg.git"
|
|
19
|
+
},
|
|
8
20
|
"bin": {
|
|
9
21
|
"contentful-fakes": "./dist/cli.js"
|
|
10
22
|
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"typings": "./dist/types.d.ts",
|
|
11
30
|
"publishConfig": {
|
|
12
31
|
"access": "public"
|
|
13
32
|
},
|
|
14
33
|
"scripts": {
|
|
15
34
|
"clean": "rimraf ./dist",
|
|
16
|
-
"test": "
|
|
17
|
-
"lint": "
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"lint": "oxlint --type-aware --fix src",
|
|
18
37
|
"precompile": "pnpm run clean",
|
|
19
38
|
"compile": "tsc --build",
|
|
20
39
|
"postcompile": "chmod +x ./dist/cli.js",
|
|
21
40
|
"watch": "tsc --build --watch"
|
|
22
41
|
},
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/jungvonmatt/contentful-ssg.git"
|
|
26
|
-
},
|
|
27
|
-
"files": [
|
|
28
|
-
"src",
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
|
-
"keywords": [
|
|
32
|
-
"fake",
|
|
33
|
-
"data",
|
|
34
|
-
"contentful"
|
|
35
|
-
],
|
|
36
|
-
"author": "Ben Zörb",
|
|
37
|
-
"license": "MIT",
|
|
38
|
-
"bugs": {
|
|
39
|
-
"url": "https://github.com/jungvonmatt/contentful-ssg/issues"
|
|
40
|
-
},
|
|
41
|
-
"homepage": "https://github.com/jungvonmatt/contentful-ssg#readme",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@faker-js/faker": "^7.3.0",
|
|
44
|
-
"@jungvonmatt/contentful-config": "
|
|
45
|
-
"@jungvonmatt/contentful-ssg": "
|
|
44
|
+
"@jungvonmatt/contentful-config": "5.0.0",
|
|
45
|
+
"@jungvonmatt/contentful-ssg": "5.0.0",
|
|
46
46
|
"casual": "^1.6.2",
|
|
47
47
|
"chalk": "^5.3.0",
|
|
48
48
|
"commander": "^11.1.0",
|
|
@@ -54,8 +54,7 @@
|
|
|
54
54
|
"@types/chance": "^1.1.3",
|
|
55
55
|
"@types/fs-extra": "^11.0.4",
|
|
56
56
|
"contentful-management": "^11.54.4",
|
|
57
|
-
"eslint": "^8.56.0",
|
|
58
57
|
"rimraf": "^5.0.5"
|
|
59
58
|
},
|
|
60
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "dfbefe2c66877ed9411bdb242327e6915f58cf3e"
|
|
61
60
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import { createFakes } from './index.js';
|
|
3
|
+
|
|
4
|
+
vi.mock('@jungvonmatt/contentful-config', () => ({
|
|
5
|
+
loadContentfulConfig: vi.fn().mockResolvedValue({
|
|
6
|
+
config: {
|
|
7
|
+
managementToken: 'mt',
|
|
8
|
+
environmentId: 'env',
|
|
9
|
+
spaceId: 'space',
|
|
10
|
+
},
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
vi.mock('@jungvonmatt/contentful-ssg/lib/contentful', async (importOriginal) => {
|
|
15
|
+
const actual = (await importOriginal()) as Record<string, unknown>;
|
|
16
|
+
return {
|
|
17
|
+
...actual,
|
|
18
|
+
getEnvironment: vi.fn().mockResolvedValue({
|
|
19
|
+
getContentTypes: vi.fn().mockResolvedValue({
|
|
20
|
+
items: [
|
|
21
|
+
{
|
|
22
|
+
sys: { id: 'page' },
|
|
23
|
+
fields: [
|
|
24
|
+
{ id: 'title', type: 'Symbol', required: true, validations: [] },
|
|
25
|
+
{ id: 'body', type: 'Text', required: false, validations: [] },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
sys: { id: 'author' },
|
|
30
|
+
fields: [{ id: 'name', type: 'Symbol', required: true, validations: [] }],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
}),
|
|
34
|
+
getEditorInterfaces: vi.fn().mockResolvedValue({
|
|
35
|
+
items: [
|
|
36
|
+
{
|
|
37
|
+
sys: { contentType: { sys: { id: 'page' } } },
|
|
38
|
+
controls: [
|
|
39
|
+
{ fieldId: 'title', widgetId: 'singleLine' },
|
|
40
|
+
{ fieldId: 'body', widgetId: 'multipleLine' },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
sys: { contentType: { sys: { id: 'author' } } },
|
|
45
|
+
controls: [{ fieldId: 'name', widgetId: 'singleLine' }],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
}),
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('createFakes', () => {
|
|
54
|
+
test('returns fake + minimal data for all content types when no filter', async () => {
|
|
55
|
+
const result = await createFakes([]);
|
|
56
|
+
expect(Object.keys(result).toSorted()).toEqual(['author', 'page']);
|
|
57
|
+
|
|
58
|
+
const [pageFull, pageMin] = result.page;
|
|
59
|
+
expect(pageFull).toHaveProperty('title');
|
|
60
|
+
expect(pageFull).toHaveProperty('body');
|
|
61
|
+
// minimal only contains required fields
|
|
62
|
+
expect(pageMin).toHaveProperty('title');
|
|
63
|
+
expect(pageMin).not.toHaveProperty('body');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('filters content types by id when ids are given', async () => {
|
|
67
|
+
const result = await createFakes(['page']);
|
|
68
|
+
expect(Object.keys(result)).toEqual(['page']);
|
|
69
|
+
});
|
|
70
|
+
});
|
package/src/lib/faker.test.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { ContentTypeFieldValidation } from 'contentful-management/types';
|
|
|
35
35
|
const getFieldInfo = (
|
|
36
36
|
id: string,
|
|
37
37
|
validations: ContentTypeFieldValidation[] = [],
|
|
38
|
-
widgetId: string = 'singleLine'
|
|
38
|
+
widgetId: string = 'singleLine',
|
|
39
39
|
): FieldInfo => ({
|
|
40
40
|
settings: { id, validations },
|
|
41
41
|
interface: { fieldId: 'id', widgetId },
|
|
@@ -153,7 +153,7 @@ describe('contentful-fakes', () => {
|
|
|
153
153
|
it('getSymbolFake (interface: urlEditor)', async () => {
|
|
154
154
|
const result = await getSymbolFake(getFieldInfo('-', [], 'urlEditor'));
|
|
155
155
|
expect(result).toMatch(
|
|
156
|
-
new RegExp('\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-/]))?$')
|
|
156
|
+
new RegExp('\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-/]))?$'),
|
|
157
157
|
);
|
|
158
158
|
});
|
|
159
159
|
|
|
@@ -166,8 +166,8 @@ describe('contentful-fakes', () => {
|
|
|
166
166
|
const result = await getSymbolFake(getFieldInfo('id'));
|
|
167
167
|
expect(result).toMatch(
|
|
168
168
|
new RegExp(
|
|
169
|
-
'[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}'
|
|
170
|
-
)
|
|
169
|
+
'[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}',
|
|
170
|
+
),
|
|
171
171
|
);
|
|
172
172
|
});
|
|
173
173
|
|
|
@@ -251,7 +251,7 @@ describe('contentful-fakes', () => {
|
|
|
251
251
|
|
|
252
252
|
it('getRichtextFake min', async () => {
|
|
253
253
|
const result = await getRichtextFake(
|
|
254
|
-
getFieldInfo('-', [{ enabledMarks: [], enabledNodeTypes: [] }])
|
|
254
|
+
getFieldInfo('-', [{ enabledMarks: [], enabledNodeTypes: [] }]),
|
|
255
255
|
);
|
|
256
256
|
|
|
257
257
|
expect(Object.keys(result)).toEqual(['node_type', 'data', 'content']);
|
|
@@ -261,7 +261,7 @@ describe('contentful-fakes', () => {
|
|
|
261
261
|
const result = await getRichtextFake(
|
|
262
262
|
getFieldInfo('-', [
|
|
263
263
|
{ enabledMarks: ['italic'], enabledNodeTypes: ['heading-1', 'heading-2'] },
|
|
264
|
-
])
|
|
264
|
+
]),
|
|
265
265
|
);
|
|
266
266
|
|
|
267
267
|
expect(Object.keys(result)).toEqual(['node_type', 'data', 'content']);
|