-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'us10_exportar_dados' of https://github.com/fga-eps-mds/…
…2024.2-LIVRO-LIVRE-USERS into us10_exportar_dados
- Loading branch information
Showing
8 changed files
with
125 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
/dist | ||
/node_modules | ||
/build | ||
|
||
package-lock.json | ||
|
||
# Logs | ||
logs | ||
|
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
MIT License | ||
Copyright (c) 2025 EPS/MDS | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
|
@@ -111,4 +111,4 @@ | |
"npm run lint" | ||
] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ExportController } from './export.controller'; | ||
import { ExportService } from './export.service'; | ||
import { Response } from 'express'; | ||
|
||
describe.skip('ExportController', () => { | ||
let controller: ExportController; | ||
let mockExportService: Partial<ExportService>; | ||
let mockResponse: Partial<Response>; | ||
|
||
beforeEach(async () => { | ||
mockExportService = { | ||
generateCsv: jest.fn(), | ||
}; | ||
|
||
mockResponse = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn(), | ||
header: jest.fn(), | ||
attachment: jest.fn(), | ||
send: jest.fn(), | ||
}; | ||
|
||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [ExportController], | ||
providers: [{ provide: ExportService, useValue: mockExportService }], | ||
}).compile(); | ||
|
||
controller = module.get<ExportController>(ExportController); | ||
}); | ||
|
||
it('should return a 400 error if no userIds are provided', async () => { | ||
await controller.exportToCsv(undefined, mockResponse as Response); | ||
|
||
expect(mockResponse.status).toHaveBeenCalledWith(400); | ||
expect(mockResponse.json).toHaveBeenCalledWith({ | ||
message: 'Parâmetro "userIds" é obrigatório.', | ||
}); | ||
}); | ||
|
||
it('should generate a CSV if userIds are provided', async () => { | ||
const mockCsv = 'id,name\n1,User One\n2,User Two'; | ||
(mockExportService.generateCsv as jest.Mock).mockResolvedValue(mockCsv); | ||
|
||
const userIds = '1,2'; | ||
|
||
await controller.exportToCsv(userIds, mockResponse as Response); | ||
|
||
expect(mockResponse.header).toHaveBeenCalledWith( | ||
'Content-Type', | ||
'text/csv', | ||
); | ||
expect(mockResponse.attachment).toHaveBeenCalledWith('export.csv'); | ||
expect(mockResponse.send).toHaveBeenCalledWith(mockCsv); | ||
}); | ||
|
||
it('should return a 500 error if an exception is thrown', async () => { | ||
const errorMessage = 'Erro inesperado'; | ||
(mockExportService.generateCsv as jest.Mock).mockRejectedValue( | ||
new Error(errorMessage), | ||
); | ||
|
||
const userIds = '1,2'; | ||
|
||
await controller.exportToCsv(userIds, mockResponse as Response); | ||
|
||
expect(mockResponse.status).toHaveBeenCalledWith(500); | ||
expect(mockResponse.json).toHaveBeenCalledWith({ | ||
message: errorMessage, | ||
}); | ||
}); | ||
}); |
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