From 0972915fd89a535384af09ca8d97669b4816d3bd Mon Sep 17 00:00:00 2001 From: David G Rosenberg Date: Mon, 22 Apr 2024 15:26:40 -0400 Subject: [PATCH] Can generate Info.plist factory with URL Types --- tests/factories/infoPlist.ts | 39 ++++++++++++++++++++++++------------ tests/unit/factories.test.ts | 10 +++++++++ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/tests/factories/infoPlist.ts b/tests/factories/infoPlist.ts index 4d0bd76..7fad8c0 100644 --- a/tests/factories/infoPlist.ts +++ b/tests/factories/infoPlist.ts @@ -1,20 +1,33 @@ import type { InfoPlist } from '@/src/types'; +import { urlTypeFactory } from '@/tests/factories/urlType'; import { faker } from '@faker-js/faker'; import { Factory } from 'fishery'; -class InfoPlistFactory extends Factory {} +class InfoPlistFactory extends Factory { + urlTypes(count: number = 1) { + return this.transient({ urlTypes: count }); + } +} -export const infoPlistFactory = InfoPlistFactory.define(() => { - const appName = faker.word.noun(); - const domain = faker.internet.domainName(); - const bundleId = domain.split(',').reverse().join('.') + '.' + appName; +export const infoPlistFactory = InfoPlistFactory.define( + ({ transientParams }) => { + const appName = faker.word.noun(); + const domain = faker.internet.domainName(); + const bundleId = domain.split(',').reverse().join('.') + '.' + appName; - const infoPlist = { - CFBundleDisplayName: appName, - CFBundleIdentifier: bundleId, - CFBundleName: appName, - CFBundleShortVersionString: faker.system.semver(), - }; + const infoPlist: InfoPlist = { + CFBundleDisplayName: appName, + CFBundleIdentifier: bundleId, + CFBundleName: appName, + CFBundleShortVersionString: faker.system.semver(), + }; - return infoPlist; -}); + if (transientParams.urlTypes) { + infoPlist.CFBundleURLTypes = urlTypeFactory.buildList( + transientParams.urlTypes, + ); + } + + return infoPlist; + }, +); diff --git a/tests/unit/factories.test.ts b/tests/unit/factories.test.ts index 411d321..718b46e 100644 --- a/tests/unit/factories.test.ts +++ b/tests/unit/factories.test.ts @@ -25,4 +25,14 @@ describe('Info.plist factory tests', () => { expect(infoPlist.CFBundleDisplayName).toBe(name); expect(infoPlist.CFBundleIdentifier).toContain(name); }); + + test('can generate Info.plist with single URL Type', () => { + const infoPlist = infoPlistFactory.urlTypes().build(); + expect(infoPlist.CFBundleURLTypes!.length).toBe(1); + }); + + test('can generate Info.plist with multiple URL Types', () => { + const infoPlist = infoPlistFactory.urlTypes(3).build(); + expect(infoPlist.CFBundleURLTypes!.length).toBe(3); + }); });