Skip to content

Commit

Permalink
Can deserialize Document Types
Browse files Browse the repository at this point in the history
  • Loading branch information
targendaz2 committed May 26, 2024
1 parent 0f56875 commit 9ee9ddb
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions src/tests/unit/macos/launchServices/serialization.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { documentTypeSchemaFactory } from '@/factories';
import { documentTypeFactory, documentTypeSchemaFactory } from '@/factories';
import { run } from '@/lib/jxaRun';
import { DocumentType } from '@/lib/macos/launchServices/interfaces';
import { DocumentTypeSchema } from '@/lib/macos/launchServices/schemas';
import { serializeDocumentType } from '@/lib/macos/launchServices/serializers';
import {
deserializeDocumentType,
serializeDocumentType,
} from '@/lib/macos/launchServices/serializers';
import { describe, expect, test } from '@jest/globals';

describe('Document Type serialization', () => {
Expand All @@ -11,10 +14,10 @@ describe('Document Type serialization', () => {

const result = await run<DocumentType>(
(
schema: DocumentTypeSchema,
documentTypeSchema: DocumentTypeSchema,
serialize: typeof serializeDocumentType,
) => {
return serialize(schema);
return serialize(documentTypeSchema);
},
documentTypeSchema,
serializeDocumentType,
Expand All @@ -38,14 +41,67 @@ describe('Document Type serialization', () => {
expect(async () => {
await run<DocumentType>(
(
schema: DocumentTypeSchema,
documentTypeSchema: DocumentTypeSchema,
serialize: typeof serializeDocumentType,
) => {
return serialize(schema);
return serialize(documentTypeSchema);
},
documentTypeSchema,
serializeDocumentType,
);
}).rejects.toThrowError();
});

test('can deserialize a valid Document Type', async () => {
const documentType = documentTypeFactory.build();

const result = await run<DocumentTypeSchema>(
(
documentType: DocumentType,
deserialize: typeof deserializeDocumentType,
) => {
return deserialize(documentType);
},
documentType,
deserializeDocumentType,
);

[
'LSHandlerContentType',
'LSHandlerPreferredVersions',
`LSHandlerRole${documentType.role}`,
].forEach((prop) => {
expect(result).toHaveProperty(prop);
});

expect(
// @ts-expect-error "DocumentTypeSchema doesn't support variable keys"
result['LSHandlerPreferredVersions'][
`LSHandlerRole${documentType.role}`
],
).toBe(documentType.appVersion);
});

test("can't deserialize an invalid Document Type", async () => {
const documentType = {
uti: 'public.html',
role: 'FakeRole',
appID: 'com.apple.Safari',
appVersion: '14.0.0.23',
type: 'FakeType',
};

expect(async () => {
await run<DocumentType>(
(
documentType: DocumentType,
deserialize: typeof deserializeDocumentType,
) => {
return deserialize(documentType);
},
documentType,
deserializeDocumentType,
);
}).rejects.toThrowError();
});
});

0 comments on commit 9ee9ddb

Please sign in to comment.