Skip to content

Commit

Permalink
Can generate Info.plist factory with URL Types
Browse files Browse the repository at this point in the history
  • Loading branch information
targendaz2 committed Apr 22, 2024
1 parent 4f7f314 commit 0972915
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
39 changes: 26 additions & 13 deletions tests/factories/infoPlist.ts
Original file line number Diff line number Diff line change
@@ -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<InfoPlist, { urlSchemes?: boolean }> {}
class InfoPlistFactory extends Factory<InfoPlist, { urlTypes?: number }> {
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;
},
);
10 changes: 10 additions & 0 deletions tests/unit/factories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 0972915

Please sign in to comment.