This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(agent): Creates payload and request to create/update translations for agents #321
Merged
pratimasakinala
merged 6 commits into
ps-locale-translation
from
ps-318-agent-translation
Apr 29, 2021
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50727e8
refactor(agent-detail, agent-service, agent model): Creates new metho…
pratimasakinala e5f2929
test(agent): tweak describe block messages for clarity
Karvel 26f3ddc
test(agent): initialize class for consistency
Karvel b6b6132
test(agent): new test values; don't use spread on locally created values
Karvel d5e60b4
refactor, test(agent-service.spec): updates the `it` description for …
pratimasakinala c870f5e
test(agent.service): moves the testAgent objects outside of the `befo…
pratimasakinala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,11 @@ import { | |
AgentRequest, | ||
IAgentDTO, | ||
IAgentRequest, | ||
IAgentTranslationRequest, | ||
AgentTranslationRequest, | ||
IAgentTranslation, | ||
IAgentTranslationList, | ||
AgentTranslation, | ||
} from '@models/agent'; | ||
import { getTranslocoModule } from '@utils/test/transloco-testing-module'; | ||
import { Logger } from '@utils/logger'; | ||
|
@@ -24,10 +29,12 @@ import { ToastrTestingModule } from '@utils/test/toastr-testing-module'; | |
? Logger.log('Unit skipped') | ||
: describe('[Unit] AgentService', () => { | ||
pratimasakinala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const route = `${environment.apiRoute}/agents`; | ||
let testAgent: IAgentDTO; | ||
let service: AgentService; | ||
let anotherTestAgent: IAgentDTO; | ||
let apiService: ApiService; | ||
let httpTestingController: HttpTestingController; | ||
let service: AgentService; | ||
let testAgent: IAgentDTO; | ||
let testAgentSetTranslation: IAgentDTO; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
|
@@ -62,7 +69,34 @@ import { ToastrTestingModule } from '@utils/test/toastr-testing-module'; | |
zipCode: '93721', | ||
}, | ||
}); | ||
anotherTestAgent = new AgentDTO({ | ||
id: 2, | ||
name: 'Test Tester Testing', | ||
email: '[email protected]', | ||
dynamicContent: { | ||
'en-US': { | ||
description: 'This is a test', | ||
}, | ||
}, | ||
phoneNumber: '5595555555', | ||
address: { | ||
address1: '123 Main St.', | ||
address2: '', | ||
city: 'Fresno', | ||
state: 'CA', | ||
zipCode: '93721', | ||
}, | ||
}); | ||
testAgentSetTranslation = { | ||
...testAgent, | ||
dynamicContent: { | ||
'es-MX': { | ||
description: 'Esto es una prueba', | ||
}, | ||
}, | ||
}; | ||
pratimasakinala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
@@ -90,8 +124,8 @@ import { ToastrTestingModule } from '@utils/test/toastr-testing-module'; | |
|
||
describe('createAgent()', () => { | ||
it('should use POST as the request method', () => { | ||
const newUser: IAgentRequest = new AgentRequest(); | ||
service.createAgent(newUser).subscribe(); | ||
const newAgent: IAgentRequest = new AgentRequest(); | ||
service.createAgent(newAgent).subscribe(); | ||
pratimasakinala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const req = httpTestingController.expectOne(route); | ||
|
||
expect(req.request.method).toBe('POST'); | ||
|
@@ -182,4 +216,152 @@ import { ToastrTestingModule } from '@utils/test/toastr-testing-module'; | |
expect(response).toEqual(expectedValue); | ||
}); | ||
}); | ||
|
||
describe('unpackAgentTranslationList', () => { | ||
it('should return empty translated content when language code requested does not exist on the agent data', () => { | ||
const agent: IAgentDTO = { ...testAgent }; | ||
const content: IAgentTranslationList = agent.dynamicContent; | ||
const expectedValue: IAgentTranslation = { | ||
description: '', | ||
}; | ||
const value: IAgentTranslation = service.unpackAgentTranslationList( | ||
content, | ||
'es-MX', | ||
); | ||
|
||
expect({ ...value }).toEqual({ ...expectedValue }); | ||
}); | ||
|
||
it('should return the translated content for the requested agent', () => { | ||
const agent: IAgentDTO = { ...testAgent }; | ||
const content: IAgentTranslationList = agent.dynamicContent; | ||
const expectedValue: IAgentTranslation = { | ||
description: 'This is a test', | ||
}; | ||
const value: IAgentTranslation = service.unpackAgentTranslationList( | ||
content, | ||
'en-US', | ||
); | ||
|
||
expect({ ...value }).toEqual({ ...expectedValue }); | ||
}); | ||
}); | ||
|
||
describe('getTranslatedAgent()', () => { | ||
it('should return the equivalent to the entire JSON value of the requested agent when the language requested does not exist on the agent data', () => { | ||
const agent: IAgentDTO = new AgentDTO({ ...testAgent }); | ||
const expectedValue: IAgentDTO = { ...testAgent }; | ||
const value: IAgentDTO = service.getTranslatedAgent(agent, 'es-MX'); | ||
|
||
expect({ ...value }).toEqual({ ...expectedValue }); | ||
pratimasakinala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('should return the requested agent with the requested translated content', () => { | ||
const translatedContent = new AgentTranslation({ | ||
description: 'This is a test', | ||
}); | ||
const agent: IAgentDTO = new AgentDTO({ ...testAgent }); | ||
const expectedValue: IAgentDTO = { | ||
...testAgent, | ||
translatedContentForDisplay: translatedContent, | ||
}; | ||
const value: IAgentDTO = service.getTranslatedAgent(agent, 'en-US'); | ||
|
||
expect({ ...value }).toEqual({ ...expectedValue }); | ||
}); | ||
}); | ||
|
||
describe('getTranslatedAgentList()', () => { | ||
it('should return the agents in the list with translated content unpacked', () => { | ||
const translatedContent = new AgentTranslation({ | ||
description: 'This is a test', | ||
}); | ||
const agentList: IAgentDTO[] = new Array<IAgentDTO>( | ||
{ ...testAgent }, | ||
{ ...anotherTestAgent }, | ||
); | ||
const expectedValue: IAgentDTO[] = [ | ||
{ | ||
...testAgent, | ||
translatedContentForDisplay: translatedContent, | ||
}, | ||
{ | ||
...anotherTestAgent, | ||
translatedContentForDisplay: translatedContent, | ||
}, | ||
]; | ||
const value: IAgentDTO[] = service.getTranslatedAgentList( | ||
agentList, | ||
'en-US', | ||
); | ||
|
||
expect(value).toEqual(expectedValue); | ||
}); | ||
}); | ||
|
||
describe('createTranslation()', () => { | ||
it('should use POST as the request method', () => { | ||
const newTranslation: IAgentTranslationRequest = new AgentTranslationRequest(); | ||
service.createTranslation(newTranslation, 1).subscribe(); | ||
const translationRoute = `${route}/1/translations`; | ||
const req = httpTestingController.expectOne(translationRoute); | ||
|
||
expect(req.request.method).toBe('POST'); | ||
}); | ||
|
||
it('should return the requested agent on creation', () => { | ||
const newAgentTranslation: IAgentTranslationRequest = new AgentTranslationRequest( | ||
{ | ||
dynamicContent: { | ||
'es-MX': { | ||
description: 'Esto es una prueba', | ||
}, | ||
}, | ||
}, | ||
); | ||
const expectedValue: IAgentDTO = { ...testAgentSetTranslation }; | ||
let response: IAgentDTO; | ||
spyOn(apiService, 'post').and.returnValue( | ||
observableOf(expectedValue), | ||
); | ||
|
||
service.createTranslation(newAgentTranslation, 1).subscribe((res) => { | ||
response = res; | ||
}); | ||
|
||
expect(response).toEqual(expectedValue); | ||
}); | ||
}); | ||
|
||
describe('updateTranslation()', () => { | ||
it('should use PUT as the request method', () => { | ||
const agentTranslation: IAgentTranslationRequest = new AgentTranslationRequest(); | ||
service.updateTranslation(agentTranslation, 1).subscribe(); | ||
const translationRoute = `${route}/1/translations`; | ||
const req = httpTestingController.expectOne(translationRoute); | ||
|
||
expect(req.request.method).toBe('PUT'); | ||
}); | ||
|
||
it('should return the requested agent on successful update', () => { | ||
const agentTranslation: IAgentTranslationRequest = new AgentTranslationRequest( | ||
{ | ||
dynamicContent: { | ||
'es-MX': { | ||
description: 'Esto es una prueba', | ||
}, | ||
}, | ||
}, | ||
); | ||
const expectedValue: IAgentDTO = { ...testAgentSetTranslation }; | ||
let response: IAgentDTO; | ||
spyOn(apiService, 'put').and.returnValue(observableOf(expectedValue)); | ||
|
||
service.updateTranslation(agentTranslation, 1).subscribe((res) => { | ||
response = res; | ||
}); | ||
|
||
expect(response).toEqual(expectedValue); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we trigger
setTranslation
and it actually goes not contain any changes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delayed response. Do you mean the form values don't change? The client will send a request to the server regardless of whether or not the payload value changes.