Tests refactor
This commit is contained in:
parent
245520fb50
commit
99134d8556
165 changed files with 911 additions and 531 deletions
175
packages/api/tests/modules/stores/stores.repository.test.ts
Normal file
175
packages/api/tests/modules/stores/stores.repository.test.ts
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { mockFind, mockFindOne, mockFindOneAndUpdate, mockSave } = vi.hoisted(() => ({
|
||||
mockFind: vi.fn(),
|
||||
mockFindOne: vi.fn(),
|
||||
mockFindOneAndUpdate: vi.fn(),
|
||||
mockSave: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/schemas/store.schema.js', () => {
|
||||
const chain = () => ({
|
||||
sort: vi.fn().mockReturnThis(),
|
||||
limit: vi.fn().mockReturnThis(),
|
||||
lean: vi.fn().mockReturnThis(),
|
||||
exec: mockFind,
|
||||
});
|
||||
const findOneChain = () => ({ lean: vi.fn().mockReturnThis(), exec: mockFindOne });
|
||||
const updateChain = () => ({ exec: mockFindOneAndUpdate });
|
||||
|
||||
class FakeModel {
|
||||
data: unknown;
|
||||
constructor(data: unknown) {
|
||||
this.data = data;
|
||||
}
|
||||
save = mockSave;
|
||||
toObject() {
|
||||
return this.data;
|
||||
}
|
||||
static find = vi.fn(() => chain());
|
||||
static findOne = vi.fn(() => findOneChain());
|
||||
static findOneAndUpdate = vi.fn(() => updateChain());
|
||||
}
|
||||
return { StoreModel: FakeModel };
|
||||
});
|
||||
|
||||
import { StoresRepository } from '../../../src/modules/stores/stores.repository.js';
|
||||
|
||||
describe(StoresRepository.name, () => {
|
||||
let repo: StoresRepository;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
repo = new StoresRepository();
|
||||
});
|
||||
|
||||
describe('findByHousehold', () => {
|
||||
it('returns paginated items', async () => {
|
||||
const items = [{ _id: 'st-1', name: 'Walgreens' }];
|
||||
mockFind.mockResolvedValue(items);
|
||||
|
||||
const result = await repo.findByHousehold('hh1', { limit: 20 });
|
||||
|
||||
expect(result.data).toEqual(items);
|
||||
expect(result.pagination.hasMore).toBe(false);
|
||||
expect(result.pagination.cursor).toBeNull();
|
||||
});
|
||||
|
||||
it('sets hasMore when more items exist', async () => {
|
||||
const items = [{ _id: 'st-1' }, { _id: 'st-2' }, { _id: 'st-3' }];
|
||||
mockFind.mockResolvedValue(items);
|
||||
|
||||
const result = await repo.findByHousehold('hh1', { limit: 2 });
|
||||
|
||||
expect(result.data).toHaveLength(2);
|
||||
expect(result.pagination.hasMore).toBe(true);
|
||||
expect(result.pagination.cursor).toBeTruthy();
|
||||
});
|
||||
|
||||
it('handles cursor pagination', async () => {
|
||||
mockFind.mockResolvedValue([]);
|
||||
|
||||
const cursor = Buffer.from('st-1').toString('base64');
|
||||
const result = await repo.findByHousehold('hh1', { cursor, limit: 20 });
|
||||
|
||||
expect(result.pagination.hasMore).toBe(false);
|
||||
});
|
||||
|
||||
it('filters by tags', async () => {
|
||||
mockFind.mockResolvedValue([]);
|
||||
|
||||
await repo.findByHousehold('hh1', { tags: 'pharmacy,online', limit: 20 });
|
||||
|
||||
expect(mockFind).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('filters by search', async () => {
|
||||
mockFind.mockResolvedValue([]);
|
||||
|
||||
await repo.findByHousehold('hh1', { search: 'cvs', limit: 20 });
|
||||
|
||||
expect(mockFind).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('skips tag filter when tags string is empty after trim', async () => {
|
||||
mockFind.mockResolvedValue([]);
|
||||
|
||||
await repo.findByHousehold('hh1', { tags: ' , ', limit: 20 });
|
||||
|
||||
expect(mockFind).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns null cursor when no data', async () => {
|
||||
mockFind.mockResolvedValue([]);
|
||||
|
||||
const result = await repo.findByHousehold('hh1', { limit: 20 });
|
||||
|
||||
expect(result.pagination.cursor).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('findById', () => {
|
||||
it('returns store when found', async () => {
|
||||
const store = { _id: 'st-1', name: 'CVS' };
|
||||
mockFindOne.mockResolvedValue(store);
|
||||
|
||||
const result = await repo.findById('st-1', 'hh1');
|
||||
|
||||
expect(result).toEqual(store);
|
||||
});
|
||||
|
||||
it('returns null when not found', async () => {
|
||||
mockFindOne.mockResolvedValue(null);
|
||||
|
||||
expect(await repo.findById('missing', 'hh1')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', () => {
|
||||
it('creates and returns store', async () => {
|
||||
const data = { name: 'Walgreens', tags: [], isActive: true };
|
||||
mockSave.mockImplementation(function (this: { toObject: () => unknown }) {
|
||||
return Promise.resolve(this);
|
||||
});
|
||||
|
||||
const result = await repo.create(data as never, 'hh1', 'user-1');
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
expect(mockSave).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('updates and returns store', async () => {
|
||||
const updated = { _id: 'st-1', name: 'Updated' };
|
||||
mockFindOneAndUpdate.mockResolvedValue(updated);
|
||||
|
||||
const result = await repo.update('st-1', 'hh1', { name: 'Updated' });
|
||||
|
||||
expect(result).toEqual(updated);
|
||||
});
|
||||
|
||||
it('returns null when not found', async () => {
|
||||
mockFindOneAndUpdate.mockResolvedValue(null);
|
||||
|
||||
expect(await repo.update('missing', 'hh1', {})).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('deactivate', () => {
|
||||
it('sets isActive=false and returns store', async () => {
|
||||
const deactivated = { _id: 'st-1', isActive: false };
|
||||
mockFindOneAndUpdate.mockResolvedValue(deactivated);
|
||||
|
||||
const result = await repo.deactivate('st-1', 'hh1');
|
||||
|
||||
expect(result).toEqual(deactivated);
|
||||
});
|
||||
|
||||
it('returns null when not found', async () => {
|
||||
mockFindOneAndUpdate.mockResolvedValue(null);
|
||||
|
||||
expect(await repo.deactivate('missing', 'hh1')).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
323
packages/api/tests/modules/stores/stores.routes.test.ts
Normal file
323
packages/api/tests/modules/stores/stores.routes.test.ts
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import Fastify from 'fastify';
|
||||
import { fastifyAwilixPlugin } from '@fastify/awilix';
|
||||
import { serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod';
|
||||
|
||||
vi.mock('jose', () => ({
|
||||
createRemoteJWKSet: vi.fn(() => 'mock-jwks'),
|
||||
jwtVerify: vi.fn().mockResolvedValue({
|
||||
payload: {
|
||||
sub: 'kc-1',
|
||||
email: 'test@example.com',
|
||||
preferred_username: 'testuser',
|
||||
realm_access: { roles: ['member'] },
|
||||
householdIds: ['hh1'],
|
||||
},
|
||||
protectedHeader: { alg: 'RS256' },
|
||||
key: {},
|
||||
}),
|
||||
}));
|
||||
|
||||
const { mockList, mockGetById, mockCreate, mockUpdate, mockDeactivate } = vi.hoisted(() => ({
|
||||
mockList: vi.fn(),
|
||||
mockGetById: vi.fn(),
|
||||
mockCreate: vi.fn(),
|
||||
mockUpdate: vi.fn(),
|
||||
mockDeactivate: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/modules/stores/stores.repository.js', () => ({
|
||||
StoresRepository: class {
|
||||
findByHousehold = vi.fn();
|
||||
findById = vi.fn();
|
||||
create = vi.fn();
|
||||
update = vi.fn();
|
||||
deactivate = vi.fn();
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/modules/stores/stores.service.js', () => ({
|
||||
StoresService: class {
|
||||
list = mockList;
|
||||
getById = mockGetById;
|
||||
create = mockCreate;
|
||||
update = mockUpdate;
|
||||
deactivate = mockDeactivate;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/modules/users/users.repository.js', () => ({
|
||||
UsersRepository: class {
|
||||
findByKeycloakId = vi.fn().mockResolvedValue({ householdIds: ['hh1'] });
|
||||
upsertFromToken = vi.fn().mockResolvedValue({ householdIds: ['hh1'] });
|
||||
},
|
||||
}));
|
||||
|
||||
import authPlugin from '../../../src/plugins/auth.plugin.js';
|
||||
import householdPlugin from '../../../src/plugins/household.plugin.js';
|
||||
import usersRoutes from '../../../src/modules/users/users.routes.js';
|
||||
import storesRoutes from '../../../src/modules/stores/stores.routes.js';
|
||||
|
||||
function makeFakeStore(overrides = {}) {
|
||||
return {
|
||||
_id: 'st-1',
|
||||
householdId: 'hh1',
|
||||
name: 'Walgreens',
|
||||
tags: ['pharmacy'],
|
||||
isActive: true,
|
||||
createdBy: 'kc-1',
|
||||
createdAt: '2024-06-01T00:00:00.000Z',
|
||||
updatedAt: '2024-06-01T00:00:00.000Z',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('stores.routes', () => {
|
||||
let app: Awaited<ReturnType<typeof buildTestApp>>;
|
||||
|
||||
async function buildTestApp() {
|
||||
const instance = Fastify({ logger: false });
|
||||
instance.setValidatorCompiler(validatorCompiler);
|
||||
instance.setSerializerCompiler(serializerCompiler);
|
||||
await instance.register(fastifyAwilixPlugin, {
|
||||
disposeOnClose: true,
|
||||
disposeOnResponse: true,
|
||||
strictBooleanEnforced: true,
|
||||
});
|
||||
await instance.register(authPlugin);
|
||||
await instance.register(householdPlugin);
|
||||
await instance.register(usersRoutes);
|
||||
await instance.register(storesRoutes);
|
||||
await instance.ready();
|
||||
return instance;
|
||||
}
|
||||
|
||||
const authHeaders = { authorization: 'Bearer valid-token' };
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
app = await buildTestApp();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (app) await app.close();
|
||||
});
|
||||
|
||||
describe('GET /api/v1/households/:householdId/stores', () => {
|
||||
it('returns paginated store list', async () => {
|
||||
mockList.mockResolvedValue({
|
||||
data: [makeFakeStore()],
|
||||
pagination: { cursor: null, hasMore: false },
|
||||
});
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/households/hh1/stores',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
expect(body.data).toHaveLength(1);
|
||||
expect(body.data[0].name).toBe('Walgreens');
|
||||
expect(body.pagination.hasMore).toBe(false);
|
||||
});
|
||||
|
||||
it('passes query params to service', async () => {
|
||||
mockList.mockResolvedValue({ data: [], pagination: { cursor: null, hasMore: false } });
|
||||
|
||||
await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/households/hh1/stores?tags=pharmacy&search=cvs&limit=5',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(mockList).toHaveBeenCalledWith(
|
||||
'hh1',
|
||||
expect.objectContaining({ tags: 'pharmacy', search: 'cvs', limit: 5 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('handles ObjectId and Date in response', async () => {
|
||||
mockList.mockResolvedValue({
|
||||
data: [
|
||||
makeFakeStore({
|
||||
_id: { toString: () => 'st-obj' },
|
||||
createdAt: new Date('2024-01-01T00:00:00.000Z'),
|
||||
updatedAt: new Date('2024-01-01T00:00:00.000Z'),
|
||||
}),
|
||||
],
|
||||
pagination: { cursor: null, hasMore: false },
|
||||
});
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/households/hh1/stores',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
expect(body.data[0]._id).toBe('st-obj');
|
||||
expect(body.data[0].createdAt).toBe('2024-01-01T00:00:00.000Z');
|
||||
});
|
||||
|
||||
it('includes optional fields in response when present', async () => {
|
||||
mockList.mockResolvedValue({
|
||||
data: [
|
||||
makeFakeStore({
|
||||
address: '123 Main St',
|
||||
location: { lat: 40.7128, lng: -74.006 },
|
||||
url: 'https://walgreens.com',
|
||||
notes: 'Open 24h',
|
||||
}),
|
||||
],
|
||||
pagination: { cursor: null, hasMore: false },
|
||||
});
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/households/hh1/stores',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
expect(body.data[0].address).toBe('123 Main St');
|
||||
expect(body.data[0].location).toEqual({ lat: 40.7128, lng: -74.006 });
|
||||
expect(body.data[0].url).toBe('https://walgreens.com');
|
||||
expect(body.data[0].notes).toBe('Open 24h');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /api/v1/households/:householdId/stores/:id', () => {
|
||||
it('returns single store', async () => {
|
||||
mockGetById.mockResolvedValue(makeFakeStore());
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/households/hh1/stores/st-1',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json().name).toBe('Walgreens');
|
||||
});
|
||||
|
||||
it('passes id and householdId to service', async () => {
|
||||
mockGetById.mockResolvedValue(makeFakeStore());
|
||||
|
||||
await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/households/hh1/stores/st-99',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(mockGetById).toHaveBeenCalledWith('st-99', 'hh1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/v1/households/:householdId/stores', () => {
|
||||
it('creates store and returns 201', async () => {
|
||||
mockCreate.mockResolvedValue(makeFakeStore());
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/households/hh1/stores',
|
||||
headers: authHeaders,
|
||||
payload: { name: 'Walgreens' },
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(201);
|
||||
expect(res.json().name).toBe('Walgreens');
|
||||
});
|
||||
|
||||
it('passes userId to service', async () => {
|
||||
mockCreate.mockResolvedValue(makeFakeStore());
|
||||
|
||||
await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/households/hh1/stores',
|
||||
headers: authHeaders,
|
||||
payload: { name: 'CVS' },
|
||||
});
|
||||
|
||||
expect(mockCreate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'CVS' }),
|
||||
'hh1',
|
||||
'kc-1',
|
||||
);
|
||||
});
|
||||
|
||||
it('returns 400 for missing name', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/households/hh1/stores',
|
||||
headers: authHeaders,
|
||||
payload: {},
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PATCH /api/v1/households/:householdId/stores/:id', () => {
|
||||
it('updates store and returns 200', async () => {
|
||||
mockUpdate.mockResolvedValue(makeFakeStore({ name: 'CVS' }));
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'PATCH',
|
||||
url: '/api/v1/households/hh1/stores/st-1',
|
||||
headers: authHeaders,
|
||||
payload: { name: 'CVS' },
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json().name).toBe('CVS');
|
||||
});
|
||||
|
||||
it('passes id, householdId, body to service', async () => {
|
||||
mockUpdate.mockResolvedValue(makeFakeStore());
|
||||
|
||||
await app.inject({
|
||||
method: 'PATCH',
|
||||
url: '/api/v1/households/hh1/stores/st-1',
|
||||
headers: authHeaders,
|
||||
payload: { isActive: false },
|
||||
});
|
||||
|
||||
expect(mockUpdate).toHaveBeenCalledWith(
|
||||
'st-1',
|
||||
'hh1',
|
||||
expect.objectContaining({ isActive: false }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /api/v1/households/:householdId/stores/:id', () => {
|
||||
it('deactivates store and returns 200', async () => {
|
||||
mockDeactivate.mockResolvedValue(makeFakeStore({ isActive: false }));
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: '/api/v1/households/hh1/stores/st-1',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json().isActive).toBe(false);
|
||||
});
|
||||
|
||||
it('passes id and householdId to service', async () => {
|
||||
mockDeactivate.mockResolvedValue(makeFakeStore({ isActive: false }));
|
||||
|
||||
await app.inject({
|
||||
method: 'DELETE',
|
||||
url: '/api/v1/households/hh1/stores/st-1',
|
||||
headers: authHeaders,
|
||||
});
|
||||
|
||||
expect(mockDeactivate).toHaveBeenCalledWith('st-1', 'hh1');
|
||||
});
|
||||
});
|
||||
});
|
||||
113
packages/api/tests/modules/stores/stores.service.test.ts
Normal file
113
packages/api/tests/modules/stores/stores.service.test.ts
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { StoresService } from '../../../src/modules/stores/stores.service.js';
|
||||
|
||||
describe(StoresService.name, () => {
|
||||
const mockRepo = {
|
||||
findByHousehold: vi.fn(),
|
||||
findById: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
deactivate: vi.fn(),
|
||||
};
|
||||
|
||||
let service: StoresService;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
service = new StoresService({ storesRepository: mockRepo as never });
|
||||
});
|
||||
|
||||
describe('list', () => {
|
||||
it('delegates to repository', async () => {
|
||||
const result = { data: [], pagination: { cursor: null, hasMore: false } };
|
||||
mockRepo.findByHousehold.mockResolvedValue(result);
|
||||
|
||||
const response = await service.list('hh1', { limit: 20 });
|
||||
|
||||
expect(response).toEqual(result);
|
||||
expect(mockRepo.findByHousehold).toHaveBeenCalledWith('hh1', { limit: 20 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getById', () => {
|
||||
it('returns store when found', async () => {
|
||||
const store = { _id: 'st-1', name: 'Walgreens' };
|
||||
mockRepo.findById.mockResolvedValue(store);
|
||||
|
||||
expect(await service.getById('st-1', 'hh1')).toEqual(store);
|
||||
});
|
||||
|
||||
it('throws NotFoundError when not found', async () => {
|
||||
mockRepo.findById.mockResolvedValue(null);
|
||||
|
||||
await expect(service.getById('missing', 'hh1')).rejects.toThrow('Store not found');
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', () => {
|
||||
it('delegates to repository', async () => {
|
||||
const store = { _id: 'st-1', name: 'CVS' };
|
||||
mockRepo.create.mockResolvedValue(store);
|
||||
|
||||
const result = await service.create(
|
||||
{ name: 'CVS', tags: [], isActive: true } as never,
|
||||
'hh1',
|
||||
'user-1',
|
||||
);
|
||||
|
||||
expect(result).toEqual(store);
|
||||
expect(mockRepo.create).toHaveBeenCalledWith(expect.anything(), 'hh1', 'user-1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('updates and returns store', async () => {
|
||||
mockRepo.findById.mockResolvedValue({ _id: 'st-1' });
|
||||
const updated = { _id: 'st-1', name: 'CVS' };
|
||||
mockRepo.update.mockResolvedValue(updated);
|
||||
|
||||
const result = await service.update('st-1', 'hh1', { name: 'CVS' });
|
||||
|
||||
expect(result).toEqual(updated);
|
||||
});
|
||||
|
||||
it('throws NotFoundError on initial lookup failure', async () => {
|
||||
mockRepo.findById.mockResolvedValue(null);
|
||||
|
||||
await expect(service.update('missing', 'hh1', {})).rejects.toThrow('Store not found');
|
||||
});
|
||||
|
||||
it('throws NotFoundError when update returns null', async () => {
|
||||
mockRepo.findById.mockResolvedValue({ _id: 'st-1' });
|
||||
mockRepo.update.mockResolvedValue(null);
|
||||
|
||||
await expect(service.update('st-1', 'hh1', {})).rejects.toThrow('Store not found');
|
||||
});
|
||||
});
|
||||
|
||||
describe('deactivate', () => {
|
||||
it('deactivates and returns store', async () => {
|
||||
mockRepo.findById.mockResolvedValue({ _id: 'st-1' });
|
||||
const deactivated = { _id: 'st-1', isActive: false };
|
||||
mockRepo.deactivate.mockResolvedValue(deactivated);
|
||||
|
||||
const result = await service.deactivate('st-1', 'hh1');
|
||||
|
||||
expect(result).toEqual(deactivated);
|
||||
expect(mockRepo.deactivate).toHaveBeenCalledWith('st-1', 'hh1');
|
||||
});
|
||||
|
||||
it('throws NotFoundError when store not found', async () => {
|
||||
mockRepo.findById.mockResolvedValue(null);
|
||||
|
||||
await expect(service.deactivate('missing', 'hh1')).rejects.toThrow('Store not found');
|
||||
});
|
||||
|
||||
it('throws NotFoundError when deactivate returns null', async () => {
|
||||
mockRepo.findById.mockResolvedValue({ _id: 'st-1' });
|
||||
mockRepo.deactivate.mockResolvedValue(null);
|
||||
|
||||
await expect(service.deactivate('st-1', 'hh1')).rejects.toThrow('Store not found');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue