feat(security): harden the API, trust Hiboutik for deletions, lock syncs (#3)
This commit is contained in:
@@ -89,12 +89,21 @@ describe('ProductHiboutikService', () => {
|
||||
expect(calls[0]).toBe('deleteProducts');
|
||||
});
|
||||
|
||||
it('does not delete anything when Hiboutik returns no products', async () => {
|
||||
it('deletes every product when Hiboutik answers with an empty list', async () => {
|
||||
productHiboutikRepository.getProducts.mockResolvedValue([]);
|
||||
productDatabaseRepository.getAll.mockResolvedValue([{ id: 'uuid-1', hiboutikId: 1 }]);
|
||||
|
||||
await service.syncProducts();
|
||||
|
||||
expect(productDatabaseRepository.deleteAll).toHaveBeenCalledWith(['uuid-1']);
|
||||
});
|
||||
|
||||
it('deletes nothing when the Hiboutik call fails', async () => {
|
||||
productHiboutikRepository.getProducts.mockRejectedValue(new Error('Request failed with status code 500'));
|
||||
productDatabaseRepository.getAll.mockResolvedValue([{ id: 'uuid-1', hiboutikId: 1 }]);
|
||||
|
||||
await expect(service.syncProducts()).rejects.toThrow('500');
|
||||
|
||||
expect(productDatabaseRepository.deleteAll).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user