Skip to content

Commit

Permalink
feat: implement PublishableItemTypeChecker to check if type is publis…
Browse files Browse the repository at this point in the history
…hable (#548)
  • Loading branch information
ReidyT authored Jun 13, 2024
1 parent 2ebee02 commit 323834c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/itemPublished/itemPublished.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';

import { PublishableItemTypeChecker } from './itemPublished.js';
import { ItemType } from '@/item/itemType.js';

describe('ItemPublished', () => {
describe('PublishableItemTypeChecker', () => {
describe('Authorized item types to be published', () => {
it('"Folder" type is allowed to be published', () => {
expect(
PublishableItemTypeChecker.isItemTypeAllowedToBePublished(
ItemType.FOLDER,
),
).toBeTruthy();
});
});

describe('Unauthorized item types to be published', () => {
const unauthorizedTypes = Object.values(ItemType).filter(
(t) => !PublishableItemTypeChecker.isItemTypeAllowedToBePublished(t),
);

it.each(unauthorizedTypes)(
'Item type "%s" is not allowed to be published',
(type) => {
expect(unauthorizedTypes).includes(type);
expect(
PublishableItemTypeChecker.isItemTypeAllowedToBePublished(type),
).toBeFalsy();
},
);
});
});
});
24 changes: 23 additions & 1 deletion src/itemPublished/itemPublished.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { DiscriminatedItem, Member, PackedItem } from '../index.js';
import {
DiscriminatedItem,
ItemType,
ItemTypeUnion,
Member,
PackedItem,
} from '../index.js';
import { UUID } from '@/types.js';

export interface ItemPublished {
Expand All @@ -16,3 +22,19 @@ export interface PackedItemPublished {
item: PackedItem;
totalViews: number;
}

export class PublishableItemTypeChecker {
private static readonly ALLOWED_PUBLISHING_TYPES: ItemTypeUnion[] = [
ItemType.FOLDER,
];

public static isItemTypeAllowedToBePublished(itemType: ItemTypeUnion) {
return PublishableItemTypeChecker.ALLOWED_PUBLISHING_TYPES.includes(
itemType,
);
}

public static getAllowedTypes() {
return Array.from(PublishableItemTypeChecker.ALLOWED_PUBLISHING_TYPES);
}
}

0 comments on commit 323834c

Please sign in to comment.