Skip to content

Commit

Permalink
fix: from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Defferrard committed Aug 20, 2024
1 parent 54634af commit dcdb20a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/itemLogin/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ItemLoginSchema, ItemLoginSchemaType } from './itemLogin.js';
import { faker } from '@faker-js/faker';

export function itemLoginSchemaFactory(
export function ItemLoginSchemaFactory(
itemLoginSchema: Partial<ItemLoginSchema> & Pick<ItemLoginSchema, 'item'>,
): ItemLoginSchema {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/itemMembership/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ItemMembershipFactory = (
id: faker.string.uuid(),
createdAt: faker.date.anytime().toISOString(),
updatedAt: faker.date.anytime().toISOString(),
account: im.account || MemberFactory(),
account: im.account ?? MemberFactory(),
permission: faker.helpers.enumValue(PermissionLevel),
...im,
});
12 changes: 10 additions & 2 deletions src/itemMembership/itemMembership.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { DiscriminatedItem } from '@/item/item.js';
import { AugmentedAccount } from '@/member/member.js';
import { Account, AccountType, Member } from '@/member/member.js';
import { UUID } from '@/types.js';

type AugmentedAccount =
| (Member & {
type: AccountType.Individual;
})
| (Account & {
type: AccountType.Guest;
});

export interface ItemMembership {
id: UUID;
account: AugmentedAccount;
item: DiscriminatedItem;
permission: PermissionLevel;
creator?: AugmentedAccount | null;
creator?: Account | null;
createdAt: string;
updatedAt: string;
}
14 changes: 7 additions & 7 deletions src/member/factory.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {
Account,
BaseAccount,
AccountType,
CompleteAccount,
CompleteGuest,
CompleteMember,
MemberType,
} from './member.js';
import { faker } from '@faker-js/faker';

export function AccountFactory(account: Partial<Account> = {}): Account {
return { id: faker.string.uuid(), name: faker.person.fullName(), ...account };
}

function baseAccountFactory<T extends MemberType>(
baseAccount: Partial<BaseAccount> & { type: T },
): BaseAccount & { type: T } {
function BaseAccountFactory<T extends AccountType>(
baseAccount: Partial<CompleteAccount> & { type: T },
): CompleteAccount & { type: T } {
return {
...AccountFactory(baseAccount),
createdAt: faker.date.anytime().toISOString(),
Expand All @@ -32,13 +32,13 @@ export const MemberFactory = (
]),
enableSaveActions: m.enableSaveActions ?? true,
isValidated: m.isValidated ?? true,
...baseAccountFactory({ type: MemberType.Individual }),
...BaseAccountFactory({ type: AccountType.Individual }),
...m,
});

export const GuestFactory = (
g: Partial<CompleteGuest> & Pick<CompleteGuest, 'itemLoginSchema'>,
): CompleteGuest => ({
...baseAccountFactory({ type: MemberType.Guest }),
...BaseAccountFactory({ type: AccountType.Guest }),
...g,
});
8 changes: 4 additions & 4 deletions src/member/member.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { MemberType, isPseudoMember } from './member.js';
import { AccountType, isPseudoMember } from './member.js';

describe('Member Util Tests', () => {
beforeEach(() => {
Expand All @@ -9,14 +9,14 @@ describe('Member Util Tests', () => {

describe('isPseudoMember', () => {
it('check successfully member is pseudonymized for false values', () => {
const res1 = isPseudoMember({ type: MemberType.Individual });
const res1 = isPseudoMember({ type: AccountType.Individual });
expect(res1).toBeFalsy();
const res2 = isPseudoMember({ type: MemberType.Group });
const res2 = isPseudoMember({ type: AccountType.Group });
expect(res2).toBeFalsy();
});

it('check successfully member is pseudonymized for true values', () => {
const res3 = isPseudoMember({ type: MemberType.Guest });
const res3 = isPseudoMember({ type: AccountType.Guest });
expect(res3).toBeTruthy();
});
});
Expand Down
42 changes: 14 additions & 28 deletions src/member/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type PublicProfile = {
updatedAt: string;
};

export enum MemberType {
export enum AccountType {
Individual = 'individual',
Group = 'group',
Guest = 'guest',
Expand All @@ -58,33 +58,19 @@ export type Account = {
name: string;
};

type AccountTypeProperty = {
type: `${MemberType}` | MemberType;
};

export type Member = Account & {
email: string;
};

export type Guest = Account;

export type AugmentedAccount =
| (Member & {
type: MemberType.Individual;
})
| (Guest & {
type: MemberType.Guest;
});

export type BaseAccount = Account &
AccountTypeProperty & {
createdAt: string;
updatedAt: string;
lastAuthenticatedAt?: string;
};
export type CompleteAccount = Account & {
type: `${AccountType}` | AccountType;
createdAt: string;
updatedAt: string;
lastAuthenticatedAt?: string;
};

export type CompleteMember = BaseAccount & {
type: MemberType.Individual;
export type CompleteMember = CompleteAccount & {
type: AccountType.Individual;
email: string;
extra: MemberExtra;
enableSaveActions: boolean;
Expand All @@ -93,13 +79,13 @@ export type CompleteMember = BaseAccount & {
isValidated: boolean;
};

export type CompleteGuest = BaseAccount & {
type: MemberType.Guest;
export type CompleteGuest = CompleteAccount & {
type: AccountType.Guest;
itemLoginSchema: ItemLoginSchema;
};

export type CompleteAccount = CompleteMember | CompleteGuest;
export type CurrentAccount = CompleteMember | CompleteGuest;

export function isPseudoMember(member: { type: MemberType }) {
return member.type === MemberType.Guest;
export function isPseudoMember(member: { type: AccountType }) {
return member.type === AccountType.Guest;
}

0 comments on commit dcdb20a

Please sign in to comment.