Skip to content

Commit 9514470

Browse files
committed
Update test-runs.service.spec.ts
1 parent a7ec5b1 commit 9514470

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

src/test-runs/test-runs.service.spec.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ describe('TestRunsService', () => {
159159
branchName: 'master',
160160
baselineBranchName: 'master',
161161
comment: 'some comment',
162+
merge: false
162163
};
163164
const testRunUpdateMock = jest.fn();
164165
const testRunFindOneMock = jest.fn().mockResolvedValueOnce(testRun);
@@ -178,7 +179,79 @@ describe('TestRunsService', () => {
178179
service.findOne = testRunFindOneMock;
179180
service.emitUpdateBuildEvent = jest.fn();
180181

181-
await service.approve(testRun.id);
182+
await service.approve(testRun.id, false);
183+
184+
expect(testRunFindOneMock).toHaveBeenCalledWith(testRun.id);
185+
expect(getImageMock).toHaveBeenCalledWith(testRun.imageName);
186+
expect(saveImageMock).toHaveBeenCalledTimes(1);
187+
expect(testRunUpdateMock).toHaveBeenCalledWith({
188+
where: { id: testRun.id },
189+
data: {
190+
status: TestStatus.approved,
191+
testVariation: {
192+
update: {
193+
baselineName,
194+
baselines: {
195+
create: {
196+
baselineName,
197+
testRun: {
198+
connect: {
199+
id: testRun.id,
200+
},
201+
},
202+
},
203+
},
204+
},
205+
},
206+
},
207+
});
208+
expect(service.emitUpdateBuildEvent).toBeCalledWith(testRun.buildId);
209+
});
210+
211+
it('should approve merge', async () => {
212+
const testRun: TestRun = {
213+
id: 'id',
214+
imageName: 'imageName',
215+
diffName: 'diffName',
216+
baselineName: 'baselineName',
217+
diffPercent: 1,
218+
pixelMisMatchCount: 10,
219+
diffTollerancePercent: 12,
220+
status: TestStatus.new,
221+
buildId: 'buildId',
222+
testVariationId: 'testVariationId',
223+
updatedAt: new Date(),
224+
createdAt: new Date(),
225+
name: 'test run name',
226+
ignoreAreas: '[]',
227+
browser: 'browser',
228+
device: 'device',
229+
os: 'os',
230+
viewport: 'viewport',
231+
branchName: 'develop',
232+
baselineBranchName: 'master',
233+
comment: 'some comment',
234+
merge: false
235+
};
236+
const testRunUpdateMock = jest.fn();
237+
const testRunFindOneMock = jest.fn().mockResolvedValueOnce(testRun);
238+
const baselineName = 'some baseline name';
239+
const saveImageMock = jest.fn().mockReturnValueOnce(baselineName);
240+
const getImageMock = jest.fn().mockReturnValueOnce(
241+
new PNG({
242+
width: 10,
243+
height: 10,
244+
})
245+
);
246+
service = await initService({
247+
testRunUpdateMock,
248+
saveImageMock,
249+
getImageMock,
250+
});
251+
service.findOne = testRunFindOneMock;
252+
service.emitUpdateBuildEvent = jest.fn();
253+
254+
await service.approve(testRun.id, true);
182255

183256
expect(testRunFindOneMock).toHaveBeenCalledWith(testRun.id);
184257
expect(getImageMock).toHaveBeenCalledWith(testRun.imageName);
@@ -232,6 +305,7 @@ describe('TestRunsService', () => {
232305
branchName: 'develop',
233306
baselineBranchName: 'master',
234307
comment: 'some comment',
308+
merge: false,
235309
testVariation: {
236310
id: '123',
237311
projectId: 'project Id',
@@ -285,7 +359,7 @@ describe('TestRunsService', () => {
285359
service.findOne = testRunFindOneMock;
286360
service.emitUpdateBuildEvent = jest.fn();
287361

288-
await service.approve(testRun.id);
362+
await service.approve(testRun.id, false);
289363

290364
expect(testRunFindOneMock).toHaveBeenCalledWith(testRun.id);
291365
expect(getImageMock).toHaveBeenCalledWith(testRun.imageName);
@@ -342,6 +416,7 @@ describe('TestRunsService', () => {
342416
device: 'device',
343417
diffTollerancePercent: undefined,
344418
branchName: 'develop',
419+
merge: true,
345420
};
346421
const testRunWithResult = {
347422
id: 'id',
@@ -435,6 +510,7 @@ describe('TestRunsService', () => {
435510
baselineBranchName: testVariation.branchName,
436511
branchName: createTestRequestDto.branchName,
437512
diffTollerancePercent: createTestRequestDto.diffTollerancePercent,
513+
merge: createTestRequestDto.merge,
438514
status: TestStatus.new,
439515
},
440516
});
@@ -773,6 +849,7 @@ describe('TestRunsService', () => {
773849
comment: 'some comment',
774850
baselineBranchName: 'master',
775851
branchName: 'develop',
852+
merge: false,
776853
},
777854
],
778855
};
@@ -845,6 +922,7 @@ describe('TestRunsService', () => {
845922
comment: 'some comment',
846923
baselineBranchName: 'master',
847924
branchName: 'develop',
925+
merge: false,
848926
};
849927
const testVariationFindOrCreateMock = jest.fn().mockResolvedValueOnce(testVariation);
850928
const testRunFindManyMock = jest.fn().mockResolvedValueOnce([testRun]);

0 commit comments

Comments
 (0)