Skip to content

Commit

Permalink
Created URL Type factory
Browse files Browse the repository at this point in the history
  • Loading branch information
targendaz2 committed Apr 22, 2024
1 parent d170f54 commit 4f7f314
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"name": "MDMs",
"description": "Mobile Device Management (MDM) solution terms and concepts.",
"path": "./dicts/MDMs.txt"
},
{
"name": "URLSchemes",
"description": "URL schemes",
"path": "./dicts/URLSchemes.txt"
}
],
"dictionaries": [
Expand All @@ -21,7 +26,8 @@
"misc",
"node",
"npm",
"typescript"
"typescript",
"URLSchemes"
],
"words": ["dgrdev", "MSDA"],
"ignoreWords": [
Expand Down
36 changes: 36 additions & 0 deletions dicts/URLSchemes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
chrome
facetime
fax
file
ftp
git
http
https
imap
jabber
ldap
ldaps
mailto
maps
ms-access
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
1 change: 0 additions & 1 deletion dicts/macOS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ preboot
Sonoma
UTI
UTIs
WebCal
1 change: 1 addition & 0 deletions tests/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { infoPlistFactory } from './infoPlist';
export { urlTypeFactory } from './urlType';
8 changes: 6 additions & 2 deletions tests/factories/infoPlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import type { InfoPlist } from '@/src/types';
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';

export const infoPlistFactory = Factory.define<InfoPlist>(() => {
class InfoPlistFactory extends Factory<InfoPlist, { urlSchemes?: boolean }> {}

export const infoPlistFactory = InfoPlistFactory.define(() => {
const appName = faker.word.noun();
const domain = faker.internet.domainName();
const bundleId = domain.split(',').reverse().join('.') + '.' + appName;

return {
const infoPlist = {
CFBundleDisplayName: appName,
CFBundleIdentifier: bundleId,
CFBundleName: appName,
CFBundleShortVersionString: faker.system.semver(),
};

return infoPlist;
});
49 changes: 49 additions & 0 deletions tests/factories/urlType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { URLType } from '@/src/types';
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',
]);

return {
CFBundleURLSchemes: [urlScheme],
};
});
13 changes: 12 additions & 1 deletion tests/unit/factories.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// import cp from 'node:child_process';
import { infoPlistFactory } from '@/tests/factories';
import { infoPlistFactory, urlTypeFactory } from '@/tests/factories';
import { describe, expect, test } from '@jest/globals';

describe('URL Type factory tests', () => {
test('can generate an object', () => {
urlTypeFactory.build();
});

test('generated URL Type has a URL scheme', () => {
const urlType = urlTypeFactory.build();
expect(urlType.CFBundleURLSchemes).toBeDefined();
});
});

describe('Info.plist factory tests', () => {
test('can generate an object', () => {
infoPlistFactory.build();
Expand Down

0 comments on commit 4f7f314

Please sign in to comment.