test: feedback updated on test script
This commit is contained in:
@@ -165,7 +165,7 @@ export const TEAM_ENVIRONMENT_NOT_TEAM_MEMBER =
|
||||
* User setting not found for a user
|
||||
* (UserSettingsService)
|
||||
*/
|
||||
export const USER_SETTINGS_DATA_NOT_FOUND = 'user_settings/data_not_found' as const;
|
||||
export const USER_SETTINGS_NOT_FOUND = 'user_settings/not_found' as const;
|
||||
|
||||
/**
|
||||
* User setting not found for a user
|
||||
|
||||
@@ -7,8 +7,6 @@ export type TopicDef = {
|
||||
[
|
||||
topic: `user_environment/${string}/${'created' | 'updated' | 'deleted'}`
|
||||
]: UserEnvironment;
|
||||
[
|
||||
topic: `user_settings/${string}/${'created' | 'updated' | 'deleted'}`
|
||||
]: UserSettings;
|
||||
[topic: `user_settings/${string}/${'created' | 'updated'}`]: UserSettings;
|
||||
[topic: `user_environment/${string}/deleted_many`]: number;
|
||||
};
|
||||
|
||||
@@ -2,12 +2,7 @@ import { mockDeep, mockReset } from 'jest-mock-extended';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
import { PubSubService } from 'src/pubsub/pubsub.service';
|
||||
import { UserSettingsService } from './user-settings.service';
|
||||
import {
|
||||
JSON_INVALID,
|
||||
USER_NOT_FOUND,
|
||||
USER_SETTINGS_NULL_SETTINGS,
|
||||
USER_SETTINGS_DATA_NOT_FOUND,
|
||||
} from 'src/errors';
|
||||
import { JSON_INVALID, USER_SETTINGS_NULL_SETTINGS } from 'src/errors';
|
||||
import { UserSettings } from './user-settings.model';
|
||||
import { User } from 'src/user/user.model';
|
||||
|
||||
@@ -30,7 +25,7 @@ const user: User = {
|
||||
const settings: UserSettings = {
|
||||
id: '1',
|
||||
userUid: user.uid,
|
||||
userSettings: JSON.stringify({ key: 'k', value: 'v' }),
|
||||
properties: JSON.stringify({ key: 'k', value: 'v' }),
|
||||
updatedOn: new Date('2022-12-19T12:43:18.635Z'),
|
||||
};
|
||||
|
||||
@@ -41,20 +36,20 @@ beforeEach(() => {
|
||||
|
||||
describe('UserSettingsService', () => {
|
||||
describe('createUserSettings', () => {
|
||||
test('should create a user setting with valid user and properties', async () => {
|
||||
test('Should resolve right and create an user setting with valid user and properties', async () => {
|
||||
mockPrisma.userSettings.create.mockResolvedValue({
|
||||
...settings,
|
||||
settings: JSON.parse(settings.userSettings),
|
||||
properties: JSON.parse(settings.properties),
|
||||
});
|
||||
|
||||
const result = await userSettingsService.createUserSettings(
|
||||
user,
|
||||
settings.userSettings,
|
||||
settings.properties,
|
||||
);
|
||||
|
||||
expect(result).toEqualRight(settings);
|
||||
});
|
||||
test('should reject for invalid properties', async () => {
|
||||
test('Should reject user settings creation for invalid properties', async () => {
|
||||
const result = await userSettingsService.createUserSettings(
|
||||
user,
|
||||
'invalid-settings',
|
||||
@@ -62,7 +57,7 @@ describe('UserSettingsService', () => {
|
||||
|
||||
expect(result).toEqualLeft(JSON_INVALID);
|
||||
});
|
||||
test('should reject for null settings', async () => {
|
||||
test('Should reject user settings creation for null properties', async () => {
|
||||
const result = await userSettingsService.createUserSettings(
|
||||
user,
|
||||
null as any,
|
||||
@@ -72,20 +67,20 @@ describe('UserSettingsService', () => {
|
||||
});
|
||||
});
|
||||
describe('updateUserSettings', () => {
|
||||
test('should update a user setting for valid user and settings', async () => {
|
||||
test('Should update a user setting for valid user and settings', async () => {
|
||||
mockPrisma.userSettings.update.mockResolvedValue({
|
||||
...settings,
|
||||
settings: JSON.parse(settings.userSettings),
|
||||
properties: JSON.parse(settings.properties),
|
||||
});
|
||||
|
||||
const result = await userSettingsService.updateUserSettings(
|
||||
user,
|
||||
settings.userSettings,
|
||||
settings.properties,
|
||||
);
|
||||
|
||||
expect(result).toEqualRight(settings);
|
||||
});
|
||||
test('should reject for invalid stringified JSON settings', async () => {
|
||||
test('Should reject user settings updation for invalid stringified JSON settings', async () => {
|
||||
const result = await userSettingsService.updateUserSettings(
|
||||
user,
|
||||
'invalid-settings',
|
||||
@@ -93,7 +88,7 @@ describe('UserSettingsService', () => {
|
||||
|
||||
expect(result).toEqualLeft(JSON_INVALID);
|
||||
});
|
||||
test('should reject for null settings', async () => {
|
||||
test('Should reject user settings updation for null properties', async () => {
|
||||
const result = await userSettingsService.updateUserSettings(
|
||||
user,
|
||||
null as any,
|
||||
@@ -103,10 +98,10 @@ describe('UserSettingsService', () => {
|
||||
test('should publish message over pubsub on successful update', async () => {
|
||||
mockPrisma.userSettings.update.mockResolvedValue({
|
||||
...settings,
|
||||
settings: JSON.parse(settings.userSettings),
|
||||
properties: JSON.parse(settings.properties),
|
||||
});
|
||||
|
||||
await userSettingsService.updateUserSettings(user, settings.userSettings);
|
||||
await userSettingsService.updateUserSettings(user, settings.properties);
|
||||
|
||||
expect(mockPubSub.publish).toBeCalledWith(
|
||||
`user_settings/${user.uid}/updated`,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { UserSettings } from './user-settings.model';
|
||||
import {
|
||||
USER_SETTINGS_ALREADY_EXISTS,
|
||||
USER_SETTINGS_NULL_SETTINGS,
|
||||
USER_SETTINGS_DATA_NOT_FOUND,
|
||||
USER_SETTINGS_NOT_FOUND,
|
||||
} from 'src/errors';
|
||||
|
||||
@Injectable()
|
||||
@@ -36,7 +36,7 @@ export class UserSettingsService {
|
||||
|
||||
return E.right(settings);
|
||||
} catch (e) {
|
||||
return E.left(USER_SETTINGS_DATA_NOT_FOUND);
|
||||
return E.left(USER_SETTINGS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export class UserSettingsService {
|
||||
properties: JSON.stringify(userSettings.properties),
|
||||
};
|
||||
|
||||
// Publish subscription for environment creation
|
||||
// Publish subscription for user settings creation
|
||||
await this.pubsub.publish(`user_settings/${user.uid}/created`, settings);
|
||||
|
||||
return E.right(settings);
|
||||
@@ -99,12 +99,12 @@ export class UserSettingsService {
|
||||
properties: JSON.stringify(updatedUserSettings.properties),
|
||||
};
|
||||
|
||||
// Publish subscription for environment creation
|
||||
// Publish subscription for user settings update
|
||||
await this.pubsub.publish(`user_settings/${user.uid}/updated`, settings);
|
||||
|
||||
return E.right(settings);
|
||||
} catch (e) {
|
||||
return E.left(USER_SETTINGS_DATA_NOT_FOUND);
|
||||
return E.left(USER_SETTINGS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user