fix(auth): settings and subscription settings projection

This commit is contained in:
Karol Sójko
2022-09-22 14:34:56 +02:00
parent b58cc335f2
commit d6cf8d400a
4 changed files with 28 additions and 22 deletions
@@ -17,28 +17,31 @@ describe('SettingProjector', () => {
serverEncryptionVersion: 1,
createdAt: 1,
updatedAt: 2,
sensitive: false,
} as jest.Mocked<Setting>
})
it('should create a simple projection of a setting', async () => {
const projection = await createProjector().projectSimple(setting)
expect(projection).toEqual({
expect(projection).toStrictEqual({
uuid: 'setting-uuid',
name: 'setting-name',
value: 'setting-value',
createdAt: 1,
updatedAt: 2,
sensitive: false,
})
})
it('should create a simple projection of list of settings', async () => {
const projection = await createProjector().projectManySimple([setting])
expect(projection).toEqual([
expect(projection).toStrictEqual([
{
uuid: 'setting-uuid',
name: 'setting-name',
value: 'setting-value',
createdAt: 1,
updatedAt: 2,
sensitive: false,
},
])
})
@@ -6,16 +6,16 @@ import { SimpleSetting } from '../Domain/Setting/SimpleSetting'
@injectable()
export class SettingProjector {
async projectSimple(setting: Setting): Promise<SimpleSetting> {
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
user,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
serverEncryptionVersion,
...rest
} = setting
return rest
return {
uuid: setting.uuid,
name: setting.name,
value: setting.value,
createdAt: setting.createdAt,
updatedAt: setting.updatedAt,
sensitive: setting.sensitive,
}
}
async projectManySimple(settings: Setting[]): Promise<SimpleSetting[]> {
return Promise.all(
settings.map(async (setting) => {
@@ -17,28 +17,31 @@ describe('SubscriptionSettingProjector', () => {
serverEncryptionVersion: 1,
createdAt: 1,
updatedAt: 2,
sensitive: false,
} as jest.Mocked<SubscriptionSetting>
})
it('should create a simple projection of a setting', async () => {
const projection = await createProjector().projectSimple(setting)
expect(projection).toEqual({
expect(projection).toStrictEqual({
uuid: 'setting-uuid',
name: 'setting-name',
value: 'setting-value',
createdAt: 1,
updatedAt: 2,
sensitive: false,
})
})
it('should create a simple projection of list of settings', async () => {
const projection = await createProjector().projectManySimple([setting])
expect(projection).toEqual([
expect(projection).toStrictEqual([
{
uuid: 'setting-uuid',
name: 'setting-name',
value: 'setting-value',
createdAt: 1,
updatedAt: 2,
sensitive: false,
},
])
})
@@ -6,16 +6,16 @@ import { SubscriptionSetting } from '../Domain/Setting/SubscriptionSetting'
@injectable()
export class SubscriptionSettingProjector {
async projectSimple(setting: SubscriptionSetting): Promise<SimpleSubscriptionSetting> {
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
userSubscription,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
serverEncryptionVersion,
...rest
} = setting
return rest
return {
uuid: setting.uuid,
name: setting.name,
value: setting.value,
createdAt: setting.createdAt,
updatedAt: setting.updatedAt,
sensitive: setting.sensitive,
}
}
async projectManySimple(settings: SubscriptionSetting[]): Promise<SimpleSubscriptionSetting[]> {
return Promise.all(
settings.map(async (setting) => {