Skip to content

Commit

Permalink
Extracted factory data into json files
Browse files Browse the repository at this point in the history
  • Loading branch information
targendaz2 committed Apr 23, 2024
1 parent 6215a20 commit c6275ed
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 76 deletions.
30 changes: 30 additions & 0 deletions tests/factories/data/extensionsAndMIMETypes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"aac": "audio/aac",
"css": "text/css",
"csv": "text/csv",
"gif": "image/gif",
"gz": "application/gzip",
"heic": "image/heic",
"heif": "image/heic",
"htm": "text/html",
"html": "text/html",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"js": "text/javascript",
"json": "application/json",
"m4a": "audio/aac",
"md": "text/markdown",
"mp4": "video/mp4",
"pdf": "application/pdf",
"png": "image/png",
"rtf": "application/rtf",
"tgz": "application/gzip",
"tif": "image/tiff",
"tiff": "image/tiff",
"txt": "text/plain",
"xhtml": "application/xhtml+xml",
"xml": "application/xml",
"yaml": "application/yaml",
"yml": "application/yaml",
"zip": "application/zip"
}
1 change: 1 addition & 0 deletions tests/factories/data/roles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["Editor", "Viewer", "Shell", "QLGenerator", "None", "All"]
37 changes: 37 additions & 0 deletions tests/factories/data/urlSchemes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
"chrome",
"facetime",
"fax",
"file",
"ftp",
"git",
"http",
"https",
"imap",
"jabber",
"ldap",
"ldaps",
"mailto",
"maps",
"ms-excel",
"ms-powerpoint",
"ms-remotedesktop",
"ms-word",
"msteams",
"news",
"nfs",
"notes",
"sftp",
"skype",
"slack",
"smb",
"smtp",
"spotify",
"ssh",
"steam",
"things",
"vnc",
"vscode",
"webcal",
"zoommtg"
]
44 changes: 6 additions & 38 deletions tests/factories/documentType.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,17 @@
import type { DocumentType } from '@/src/types';
import extensionsAndMIMETypes from '@/tests/factories/data/extensionsAndMIMETypes.json';
import roles from '@/tests/factories/data/roles.json';
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';

class DocumentTypeFactory extends Factory<DocumentType> {}

export const documentTypeFactory = DocumentTypeFactory.define(() => {
const [extension, mimeType] = faker.helpers.objectEntry({
aac: 'audio/aac',
css: 'text/css',
csv: 'text/csv',
gif: 'image/gif',
gz: 'application/gzip',
heic: 'image/heic',
heif: 'image/heic',
htm: 'text/html',
html: 'text/html',
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
js: 'text/javascript',
json: 'application/json',
m4a: 'audio/aac',
md: 'text/markdown',
mp4: 'video/mp4',
pdf: 'application/pdf',
png: 'image/png',
rtf: 'application/rtf',
tgz: 'application/gzip',
tif: 'image/tiff',
tiff: 'image/tiff',
txt: 'text/plain',
xhtml: 'application/xhtml+xml',
xml: 'application/xml',
yaml: 'application/yaml',
yml: 'application/yaml',
zip: 'application/zip',
});
const [extension, mimeType] = faker.helpers.objectEntry(
extensionsAndMIMETypes,
);

const role = faker.helpers.arrayElement([
'Editor',
'Viewer',
'Shell',
'QLGenerator',
'None',
'All',
]);
const role = faker.helpers.arrayElement(roles);

return {
CFBundleTypeExtensions: [extension],
Expand Down
39 changes: 2 additions & 37 deletions tests/factories/urlType.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
import type { URLType } from '@/src/types';
import urlSchemes from '@/tests/factories/data/urlSchemes.json';
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';

class URLTypeFactory extends Factory<URLType> {}

export const urlTypeFactory = URLTypeFactory.define(() => {
const urlScheme = faker.helpers.arrayElement([
'chrome',
'facetime',
'fax',
'file',
'ftp',
'git',
'http',
'https',
'imap',
'jabber',
'ldap',
'ldaps',
'mailto',
'maps',
'ms-excel',
'ms-powerpoint',
'ms-remotedesktop',
'ms-word',
'msteams',
'news',
'nfs',
'notes',
'sftp',
'skype',
'slack',
'smb',
'smtp',
'spotify',
'ssh',
'steam',
'things',
'vnc',
'vscode',
'webcal',
'zoommtg',
]);
const urlScheme = faker.helpers.arrayElement(urlSchemes);

return {
CFBundleURLSchemes: [urlScheme],
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/factories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
infoPlistFactory,
urlTypeFactory,
} from '@/tests/factories';
import extensionsAndMIMETypes from '@/tests/factories/data/extensionsAndMIMETypes.json';
import { describe, expect, test } from '@jest/globals';

describe('Document Type factory tests', () => {
Expand All @@ -15,7 +16,10 @@ describe('Document Type factory tests', () => {
const documentType = documentTypeFactory.build();
const extension = documentType.CFBundleTypeExtensions![0];

expect(documentType.CFBundleTypeMIMETypes![0]).toContain(extension);
expect(documentType.CFBundleTypeMIMETypes![0]).toBe(
// @ts-expect-error 'eslint thinks this is an any type for some reason'
extensionsAndMIMETypes[extension],
);
});

test('generated document type has a role', () => {
Expand Down

0 comments on commit c6275ed

Please sign in to comment.