|
|
@@ -0,0 +1,98 @@
|
|
|
+import { Test } from '@nestjs/testing';
|
|
|
+import { PrismaService } from '../../prisma/prisma.service';
|
|
|
+import { SimulationsService } from './simulations.service';
|
|
|
+
|
|
|
+describe('SimulationsService', () => {
|
|
|
+ let service: SimulationsService;
|
|
|
+ const prisma = {
|
|
|
+ hairTemplate: {
|
|
|
+ findMany: jest.fn(),
|
|
|
+ count: jest.fn(),
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ jest.resetAllMocks();
|
|
|
+
|
|
|
+ const moduleRef = await Test.createTestingModule({
|
|
|
+ providers: [
|
|
|
+ SimulationsService,
|
|
|
+ { provide: PrismaService, useValue: prisma },
|
|
|
+ ],
|
|
|
+ }).compile();
|
|
|
+
|
|
|
+ service = moduleRef.get(SimulationsService);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('returns only public stylist templates for the current stylist', async () => {
|
|
|
+ prisma.hairTemplate.findMany.mockResolvedValue([
|
|
|
+ {
|
|
|
+ id: BigInt(11),
|
|
|
+ templateName: 'Layer Bob',
|
|
|
+ coverUrl: 'https://cdn.example.com/bob.png',
|
|
|
+ category: 'SHORT',
|
|
|
+ tags: 'airy,bob',
|
|
|
+ description: 'short bob',
|
|
|
+ templateUrl: 'https://cdn.example.com/bob.zip',
|
|
|
+ isSystemTemplate: 'NO',
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+ prisma.hairTemplate.count.mockResolvedValue(1);
|
|
|
+
|
|
|
+ const result = await service.listTemplateOptions(BigInt(7), {
|
|
|
+ source: 'STYLIST',
|
|
|
+ page: 1,
|
|
|
+ pageSize: 12,
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(prisma.hairTemplate.findMany).toHaveBeenCalledWith(
|
|
|
+ expect.objectContaining({
|
|
|
+ where: expect.objectContaining({
|
|
|
+ isDeleted: 0,
|
|
|
+ status: 'PUBLIC',
|
|
|
+ isSystemTemplate: 'NO',
|
|
|
+ hairstylistId: BigInt(7),
|
|
|
+ }),
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ expect(result.items[0]).toMatchObject({
|
|
|
+ id: '11',
|
|
|
+ templateName: 'Layer Bob',
|
|
|
+ tags: ['airy', 'bob'],
|
|
|
+ isSystemTemplate: false,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('returns only public system templates for the system tab', async () => {
|
|
|
+ prisma.hairTemplate.findMany.mockResolvedValue([
|
|
|
+ {
|
|
|
+ id: BigInt(21),
|
|
|
+ templateName: 'Classic Medium',
|
|
|
+ coverUrl: '',
|
|
|
+ category: 'MEDIUM',
|
|
|
+ tags: '',
|
|
|
+ description: null,
|
|
|
+ templateUrl: 'https://cdn.example.com/medium.zip',
|
|
|
+ isSystemTemplate: 'YES',
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+ prisma.hairTemplate.count.mockResolvedValue(1);
|
|
|
+
|
|
|
+ const result = await service.listTemplateOptions(BigInt(7), {
|
|
|
+ source: 'SYSTEM',
|
|
|
+ page: 1,
|
|
|
+ pageSize: 12,
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(prisma.hairTemplate.findMany).toHaveBeenCalledWith(
|
|
|
+ expect.objectContaining({
|
|
|
+ where: expect.objectContaining({
|
|
|
+ isDeleted: 0,
|
|
|
+ status: 'PUBLIC',
|
|
|
+ isSystemTemplate: 'YES',
|
|
|
+ }),
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ expect(result.items[0].id).toBe('21');
|
|
|
+ });
|
|
|
+});
|