Skip to content

Commit

Permalink
Merge pull request #5 from fga-eps-mds/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
IanFPFerreira authored May 31, 2023
2 parents f4bd41a + 7045cc6 commit 1a8a878
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/tutorials/tutorials.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('TutorialsController', () => {
.mockResolvedValue(mockTutorialEntityList[0]),
updateTutorial: jest.fn().mockResolvedValue(mockUpdateTutorialDto),
deleteTutorial: jest.fn().mockResolvedValue('Deletado com sucesso'),
deleteTutorials: jest.fn().mockResolvedValue('Deletados com sucesso'),
},
},
],
Expand Down Expand Up @@ -123,4 +124,41 @@ describe('TutorialsController', () => {
expect(service.deleteTutorial).toHaveBeenCalledWith(id);
});
});

// Create two mocks for deleteTutorials
const mockTutorials = [
{
id: '1',
name: 'mockStation',
category_id: mockUuid,
filename: 'mockFile',
data: [37, 80, 68, 70, 45, 49, 46, 52, 10, 37, 226, 227, 207, 211, 10]
},
{
id: '2',
name: 'mockStation',
category_id: mockUuid,
filename: 'mockFile',
data: [37, 80, 68, 70, 45, 49, 46, 52, 10, 37, 226, 227, 207, 211, 10]
}
];


describe('deleteManyTutorials', () => {
it('should delete many tutorial entities succesfully', async () => {


const ids = mockTutorials.map(tutorial => tutorial.id);

const result = await controller.deleteTutorials(ids);

expect(result).toMatch('Deletados com sucesso');

expect(service.deleteTutorials).toHaveBeenCalledTimes(1);

expect(service.deleteTutorials).toHaveBeenCalledWith(ids);
});
}
);

});
9 changes: 9 additions & 0 deletions src/tutorials/tutorials.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UseInterceptors,
CacheInterceptor,
UploadedFile,
ParseArrayPipe,
} from '@nestjs/common';
import { TutorialsService } from './tutorials.service';
import { CreateTutorialDto } from './dto/create-tutorial.dto';
Expand Down Expand Up @@ -67,4 +68,12 @@ export class TutorialsController {
async deleteTutorial(@Param('id') id: string): Promise<string> {
return await this.tutorialService.deleteTutorial(id);
}

// Rota para excluir lista de tutoriais cadastrados em lote
@Delete(
'delete-tutorials/:ids',
)
async deleteTutorials(@Param('ids', ParseArrayPipe) ids: string[]): Promise<string> {
return await this.tutorialService.deleteTutorials(ids);
}
}
10 changes: 10 additions & 0 deletions src/tutorials/tutorials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ export class TutorialsService {
throw new InternalServerErrorException(err.message);
}
}

// Deleta uma lista de tutoriais
async deleteTutorials(ids: string[]): Promise<string> {
try {
await this.tutorialRepo.delete(ids);
return 'Deletados com sucesso';
} catch (err) {
throw new InternalServerErrorException(err.message);
}
}
}

0 comments on commit 1a8a878

Please sign in to comment.