chore: added changes to creating a history in resolvers and service method

This commit is contained in:
ankitsridhar16
2023-01-23 22:51:37 +05:30
parent a5a14f6c76
commit ebf236b387
3 changed files with 15 additions and 15 deletions

View File

@@ -22,7 +22,7 @@ export class UserHistoryResolver {
description: 'Adds a new REST/GQL request to user history', description: 'Adds a new REST/GQL request to user history',
}) })
@UseGuards(GqlAuthGuard) @UseGuards(GqlAuthGuard)
async addRequestToHistory( async createUserHistory(
@GqlUser() user: User, @GqlUser() user: User,
@Args({ @Args({
name: 'reqData', name: 'reqData',
@@ -40,7 +40,7 @@ export class UserHistoryResolver {
}) })
reqType: string, reqType: string,
): Promise<UserHistory> { ): Promise<UserHistory> {
const createdHistory = await this.userHistoryService.addRequestToHistory( const createdHistory = await this.userHistoryService.createUserHistory(
user.uid, user.uid,
reqData, reqData,
resMetadata, resMetadata,

View File

@@ -136,8 +136,8 @@ describe('UserHistoryService', () => {
).toEqual(userHistory); ).toEqual(userHistory);
}); });
}); });
describe('addRequestToHistory', () => { describe('createUserHistory', () => {
test('Should resolve right and add a REST request to users history and return a `UserHistory` object', async () => { test('Should resolve right and create a REST request to users history and return a `UserHistory` object', async () => {
userHistoryService.validateReqType('REST'); userHistoryService.validateReqType('REST');
mockPrisma.userHistory.create.mockResolvedValueOnce({ mockPrisma.userHistory.create.mockResolvedValueOnce({
userUid: 'abc', userUid: 'abc',
@@ -160,7 +160,7 @@ describe('UserHistoryService', () => {
}; };
return expect( return expect(
await userHistoryService.addRequestToHistory( await userHistoryService.createUserHistory(
'abc', 'abc',
JSON.stringify([{}]), JSON.stringify([{}]),
JSON.stringify([{}]), JSON.stringify([{}]),
@@ -168,7 +168,7 @@ describe('UserHistoryService', () => {
), ),
).toEqualRight(userHistory); ).toEqualRight(userHistory);
}); });
test('Should resolve right and add a GQL request to users history and return a `UserHistory` object', async () => { test('Should resolve right and create a GQL request to users history and return a `UserHistory` object', async () => {
userHistoryService.validateReqType('GQL'); userHistoryService.validateReqType('GQL');
mockPrisma.userHistory.create.mockResolvedValueOnce({ mockPrisma.userHistory.create.mockResolvedValueOnce({
userUid: 'abc', userUid: 'abc',
@@ -191,7 +191,7 @@ describe('UserHistoryService', () => {
}; };
return expect( return expect(
await userHistoryService.addRequestToHistory( await userHistoryService.createUserHistory(
'abc', 'abc',
JSON.stringify([{}]), JSON.stringify([{}]),
JSON.stringify([{}]), JSON.stringify([{}]),
@@ -202,7 +202,7 @@ describe('UserHistoryService', () => {
test('Should resolve left when invalid ReqType is passed', async () => { test('Should resolve left when invalid ReqType is passed', async () => {
userHistoryService.validateReqType('INVALID'); userHistoryService.validateReqType('INVALID');
return expect( return expect(
await userHistoryService.addRequestToHistory( await userHistoryService.createUserHistory(
'abc', 'abc',
JSON.stringify([{}]), JSON.stringify([{}]),
JSON.stringify([{}]), JSON.stringify([{}]),
@@ -210,7 +210,7 @@ describe('UserHistoryService', () => {
), ),
).toEqualLeft(USER_HISTORY_INVALID_REQ_TYPE); ).toEqualLeft(USER_HISTORY_INVALID_REQ_TYPE);
}); });
test('Should add a GQL request to users history and publish a created subscription', async () => { test('Should create a GQL request to users history and publish a created subscription', async () => {
userHistoryService.validateReqType('GQL'); userHistoryService.validateReqType('GQL');
mockPrisma.userHistory.create.mockResolvedValueOnce({ mockPrisma.userHistory.create.mockResolvedValueOnce({
userUid: 'abc', userUid: 'abc',
@@ -232,7 +232,7 @@ describe('UserHistoryService', () => {
isStarred: false, isStarred: false,
}; };
await userHistoryService.addRequestToHistory( await userHistoryService.createUserHistory(
'abc', 'abc',
JSON.stringify([{}]), JSON.stringify([{}]),
JSON.stringify([{}]), JSON.stringify([{}]),
@@ -244,7 +244,7 @@ describe('UserHistoryService', () => {
userHistory, userHistory,
); );
}); });
test('Should add a REST request to users history and publish a created subscription', async () => { test('Should create a REST request to users history and publish a created subscription', async () => {
userHistoryService.validateReqType('REST'); userHistoryService.validateReqType('REST');
mockPrisma.userHistory.create.mockResolvedValueOnce({ mockPrisma.userHistory.create.mockResolvedValueOnce({
userUid: 'abc', userUid: 'abc',
@@ -266,7 +266,7 @@ describe('UserHistoryService', () => {
isStarred: false, isStarred: false,
}; };
await userHistoryService.addRequestToHistory( await userHistoryService.createUserHistory(
'abc', 'abc',
JSON.stringify([{}]), JSON.stringify([{}]),
JSON.stringify([{}]), JSON.stringify([{}]),

View File

@@ -46,14 +46,14 @@ export class UserHistoryService {
} }
/** /**
* Adds a request to users history. * Creates a user history.
* @param uid Users uid * @param uid Users uid
* @param reqData the request data * @param reqData the request data
* @param resMetadata the response metadata * @param resMetadata the response metadata
* @param reqType request Type to fetch i.e. GraphQL or REST * @param reqType request Type to fetch i.e. GraphQL or REST
* @returns a `UserHistory` object * @returns a `UserHistory` object
*/ */
async addRequestToHistory( async createUserHistory(
uid: string, uid: string,
reqData: string, reqData: string,
resMetadata: string, resMetadata: string,
@@ -92,7 +92,7 @@ export class UserHistoryService {
} }
/** /**
* Stars or unstars a request in the history * Toggles star status of a user history
* @param uid Users uid * @param uid Users uid
* @param id id of the request in the history * @param id id of the request in the history
* @returns an Either of updated `UserHistory` or Error * @returns an Either of updated `UserHistory` or Error