generated from HenriqueAmorim20/GEROcuidadoAPITemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from fga-eps-mds/develop
Develop
- Loading branch information
Showing
8 changed files
with
151 additions
and
6 deletions.
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ describe('E2E - Usuario', () => { | |
email: '[email protected]', | ||
senha, | ||
admin: false, | ||
foto: '1' as any, | ||
}; | ||
|
||
beforeAll(async () => { | ||
|
@@ -33,7 +34,7 @@ describe('E2E - Usuario', () => { | |
AppModule, | ||
ClientsModule.register([ | ||
{ | ||
name: 'AUTH_CLIENT_TEST', | ||
name: 'USUARIO_CLIENT_TEST', | ||
transport: Transport.TCP, | ||
options: { | ||
host: '0.0.0.0', | ||
|
@@ -69,7 +70,7 @@ describe('E2E - Usuario', () => { | |
await app.startAllMicroservices(); | ||
await app.init(); | ||
|
||
client = app.get('AUTH_CLIENT_TEST'); | ||
client = app.get('USUARIO_CLIENT_TEST'); | ||
await client.connect(); | ||
|
||
repository = app.get<Repository<Usuario>>(getRepositoryToken(Usuario)); | ||
|
@@ -92,6 +93,7 @@ describe('E2E - Usuario', () => { | |
|
||
Object.assign(user, res.body.data); | ||
delete user.senha; | ||
delete user.foto; | ||
}); | ||
|
||
it('should not successfully add a new "usuario" when email is already registered', async () => { | ||
|
@@ -196,6 +198,26 @@ describe('E2E - Usuario', () => { | |
}); | ||
}); | ||
|
||
describe('GET TCP - api/usuario', () => { | ||
it('should find one usuario TCP', async () => { | ||
const request = client | ||
.send({ role: 'info', cmd: 'get' }, { id: user.id }) | ||
.pipe(timeout(5000)); | ||
|
||
const response = await lastValueFrom(request); | ||
expect(response.id).toBe(user.id); | ||
}); | ||
|
||
it('should find all usuario TCP', async () => { | ||
const request = client | ||
.send({ role: 'info', cmd: 'getAll' }, { ids: [user.id] }) | ||
.pipe(timeout(5000)); | ||
|
||
const response = await lastValueFrom(request); | ||
expect(response.length).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('GET - /api/usuario/:id', () => { | ||
it('should successfully get "usuario" by id', async () => { | ||
const res = await request(app.getHttpServer()) | ||
|
@@ -206,7 +228,9 @@ describe('E2E - Usuario', () => { | |
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.message).toBeNull(); | ||
expect(res.body.data).toMatchObject(user); | ||
const data = res.body.data; | ||
delete data.foto; | ||
expect(data).toMatchObject(user); | ||
}); | ||
|
||
it('should return status 400 when id is invalid', async () => { | ||
|
@@ -252,7 +276,7 @@ describe('E2E - Usuario', () => { | |
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.message).toBeNull(); | ||
expect(res.body.data).toEqual([user]); | ||
expect(res.body.data.length).toEqual(1); | ||
}); | ||
}); | ||
|
||
|
@@ -270,7 +294,9 @@ describe('E2E - Usuario', () => { | |
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.message).toBe('Atualizado com sucesso!'); | ||
expect(res.body.data).toMatchObject(user); | ||
const data = res.body.data; | ||
delete data.foto; | ||
expect(data).toMatchObject(user); | ||
}); | ||
}); | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,20 @@ describe('UsuarioService', () => { | |
expect(found).toEqual({ id: 1, nome: 'Henrique' }); | ||
}); | ||
|
||
it('should update Usuario with photo', async () => { | ||
jest.spyOn(repository, 'findOneOrFail').mockReturnValue({ id: 1 } as any); | ||
jest | ||
.spyOn(repository, 'save') | ||
.mockReturnValue({ id: 1, nome: 'Henrique', foto: '1' } as any); | ||
|
||
const found = await service.update(1, { nome: 'Henrique' }); | ||
expect(found).toEqual({ | ||
id: 1, | ||
nome: 'Henrique', | ||
foto: 'data:image/png;base64,1', | ||
}); | ||
}); | ||
|
||
describe('findAll', () => { | ||
const usuario = { | ||
id: 1, | ||
|
@@ -169,4 +183,29 @@ describe('UsuarioService', () => { | |
expect((data as Usuario[])[0]).toEqual(usuario); | ||
}); | ||
}); | ||
|
||
describe('findAllToPublicacao', () => { | ||
const usuario = { | ||
id: 1, | ||
nome: 'Henrique', | ||
email: '[email protected]', | ||
foto: '1', | ||
}; | ||
|
||
it('should findAllToPublicacao', async () => { | ||
jest.spyOn(repository, 'createQueryBuilder').mockReturnValue({ | ||
where: () => ({ | ||
getMany: jest.fn().mockResolvedValueOnce([usuario]), | ||
}), | ||
} as any); | ||
|
||
const expectedUser = { | ||
...usuario, | ||
foto: 'data:image/png;base64,1', | ||
}; | ||
|
||
const data = await service.findAllToPublicacao([1]); | ||
expect(data).toEqual([expectedUser]); | ||
}); | ||
}); | ||
}); |
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