@@ -155,7 +155,7 @@ describe('TestRunsService', () => {
155155 } ) ;
156156 } ) ;
157157
158- describe ( 'create' , ( ) => {
158+ it ( 'create' , async ( ) => {
159159 const initCreateTestRequestDto : CreateTestRequestDto = {
160160 buildId : 'buildId' ,
161161 projectId : 'projectId' ,
@@ -177,177 +177,90 @@ describe('TestRunsService', () => {
177177 status : TestStatus . unresolved ,
178178 } ;
179179
180- it ( 'no baseline' , async ( ) => {
181- const testRun = {
182- id : 'id' ,
183- imageName : 'imageName' ,
184- baselineName : null ,
185- diffTollerancePercent : 1 ,
186- ignoreAreas : '[]' ,
187- diffName : null ,
188- } ;
180+ const testRun = {
181+ id : 'id' ,
182+ imageName : 'imageName' ,
183+ baselineName : 'baselineName' ,
184+ diffTollerancePercent : 1 ,
185+ ignoreAreas : '[]' ,
186+ diffName : null ,
187+ } ;
188+ const testVariation = {
189+ id : '123' ,
190+ projectId : 'project Id' ,
191+ name : 'Test name' ,
192+ baselineName : 'baselineName' ,
193+ os : 'OS' ,
194+ browser : 'browser' ,
195+ viewport : 'viewport' ,
196+ device : 'device' ,
197+ ignoreAreas : '[]' ,
198+ createdAt : new Date ( ) ,
199+ updatedAt : new Date ( ) ,
200+ } ;
201+ const createTestRequestDto = initCreateTestRequestDto ;
202+ const testRunCreateMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
203+ const imageName = 'image name' ;
204+ const saveImageMock = jest . fn ( ) . mockReturnValueOnce ( imageName ) ;
205+ const image = 'image' ;
206+ const baseline = 'baseline' ;
207+ const getImageMock = jest
208+ . fn ( )
209+ . mockReturnValueOnce ( baseline )
210+ . mockReturnValueOnce ( image ) ;
211+ const eventNewTestRunMock = jest . fn ( ) ;
212+ service = await initService ( { testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock } ) ;
213+ const diffResult : DiffResult = {
214+ status : TestStatus . unresolved ,
215+ diffName : 'diff image name' ,
216+ pixelMisMatchCount : 11 ,
217+ diffPercent : 22 ,
218+ isSameDimension : true ,
219+ } ;
220+ const getDiffMock = jest . fn ( ) . mockReturnValueOnce ( diffResult ) ;
221+ service . getDiff = getDiffMock ;
222+ const saveDiffResultMock = jest . fn ( ) ;
223+ service . saveDiffResult = saveDiffResultMock . mockResolvedValueOnce ( testRunWithResult ) ;
189224
190- const testVariation = {
191- id : '123' ,
192- projectId : 'project Id' ,
193- name : 'Test name' ,
194- baselineName : null ,
195- os : 'OS' ,
196- browser : 'browser' ,
197- viewport : 'viewport' ,
198- device : 'device' ,
199- ignoreAreas : '[]' ,
200- createdAt : new Date ( ) ,
201- updatedAt : new Date ( ) ,
202- } ;
203- const diffResult : DiffResult = {
204- status : null ,
205- diffName : null ,
206- pixelMisMatchCount : null ,
207- diffPercent : null ,
208- isSameDimension : false ,
209- } ;
210- const createTestRequestDto = initCreateTestRequestDto ;
211- const testRunCreateMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
212- const imageName = 'image name' ;
213- const saveImageMock = jest . fn ( ) . mockReturnValueOnce ( imageName ) ;
214- const image = 'image' ;
215- const baseline = null ;
216- const getImageMock = jest
217- . fn ( )
218- . mockReturnValueOnce ( baseline )
219- . mockReturnValueOnce ( image ) ;
220- const eventNewTestRunMock = jest . fn ( ) ;
221- service = await initService ( { testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock } ) ;
222- const getDiffMock = jest . fn ( ) . mockReturnValueOnce ( diffResult ) ;
223- service . getDiff = getDiffMock ;
224- const saveDiffResultMock = jest . fn ( ) . mockResolvedValueOnce ( testRunWithResult ) ;
225- service . saveDiffResult = saveDiffResultMock ;
226-
227- const result = await service . create ( testVariation , createTestRequestDto ) ;
228-
229- expect ( saveImageMock ) . toHaveBeenCalledWith ( 'screenshot' , Buffer . from ( createTestRequestDto . imageBase64 , 'base64' ) ) ;
230- expect ( getImageMock ) . toHaveBeenNthCalledWith ( 1 , testVariation . baselineName ) ;
231- expect ( getImageMock ) . toHaveBeenNthCalledWith ( 2 , imageName ) ;
232- expect ( getDiffMock ) . toHaveBeenCalledWith ( baseline , image , testRun . diffTollerancePercent , testRun . ignoreAreas ) ;
233- expect ( saveDiffResultMock ) . toHaveBeenCalledWith ( testRun . id , diffResult ) ;
234- expect ( testRunCreateMock ) . toHaveBeenCalledWith ( {
235- data : {
236- imageName,
237- testVariation : {
238- connect : {
239- id : testVariation . id ,
240- } ,
241- } ,
242- build : {
243- connect : {
244- id : createTestRequestDto . buildId ,
245- } ,
246- } ,
247- name : testVariation . name ,
248- browser : testVariation . browser ,
249- device : testVariation . device ,
250- os : testVariation . os ,
251- viewport : testVariation . viewport ,
252- baselineName : testVariation . baselineName ,
253- ignoreAreas : testVariation . ignoreAreas ,
254- diffTollerancePercent : createTestRequestDto . diffTollerancePercent ,
255- diffName : undefined ,
256- pixelMisMatchCount : undefined ,
257- diffPercent : undefined ,
258- status : TestStatus . new ,
259- } ,
260- } ) ;
261- expect ( eventNewTestRunMock ) . toHaveBeenCalledWith ( testRunWithResult ) ;
262- expect ( result ) . toBe ( testRunWithResult ) ;
263- } ) ;
225+ const result = await service . create ( testVariation , createTestRequestDto ) ;
264226
265- it ( 'with baseline' , async ( ) => {
266- const testRun = {
267- id : 'id' ,
268- imageName : 'imageName' ,
269- baselineName : 'baselineName' ,
270- diffTollerancePercent : 1 ,
271- ignoreAreas : '[]' ,
272- diffName : null ,
273- } ;
274- const testVariation = {
275- id : '123' ,
276- projectId : 'project Id' ,
277- name : 'Test name' ,
278- baselineName : 'baselineName' ,
279- os : 'OS' ,
280- browser : 'browser' ,
281- viewport : 'viewport' ,
282- device : 'device' ,
283- ignoreAreas : '[]' ,
284- createdAt : new Date ( ) ,
285- updatedAt : new Date ( ) ,
286- } ;
287- const createTestRequestDto = initCreateTestRequestDto ;
288- const testRunCreateMock = jest . fn ( ) . mockResolvedValueOnce ( testRun ) ;
289- const imageName = 'image name' ;
290- const saveImageMock = jest . fn ( ) . mockReturnValueOnce ( imageName ) ;
291- const image = 'image' ;
292- const baseline = 'baseline' ;
293- const getImageMock = jest
294- . fn ( )
295- . mockReturnValueOnce ( baseline )
296- . mockReturnValueOnce ( image ) ;
297- const eventNewTestRunMock = jest . fn ( ) ;
298- service = await initService ( { testRunCreateMock, saveImageMock, getImageMock, eventNewTestRunMock } ) ;
299- const diffResult : DiffResult = {
300- status : TestStatus . unresolved ,
301- diffName : 'diff image name' ,
302- pixelMisMatchCount : 11 ,
303- diffPercent : 22 ,
304- isSameDimension : true ,
305- } ;
306- const getDiffMock = jest . fn ( ) . mockReturnValueOnce ( diffResult ) ;
307- service . getDiff = getDiffMock ;
308- const saveDiffResultMock = jest . fn ( ) ;
309- service . saveDiffResult = saveDiffResultMock . mockResolvedValueOnce ( testRunWithResult ) ;
310-
311- const result = await service . create ( testVariation , createTestRequestDto ) ;
312-
313- expect ( saveImageMock ) . toHaveBeenCalledWith ( 'screenshot' , Buffer . from ( createTestRequestDto . imageBase64 , 'base64' ) ) ;
314- expect ( service . getDiff ) . toHaveBeenCalledWith (
315- baseline ,
316- image ,
317- createTestRequestDto . diffTollerancePercent ,
318- testVariation . ignoreAreas
319- ) ;
320- expect ( getImageMock ) . toHaveBeenNthCalledWith ( 1 , testVariation . baselineName ) ;
321- expect ( getImageMock ) . toHaveBeenNthCalledWith ( 2 , imageName ) ;
322- expect ( testRunCreateMock ) . toHaveBeenCalledWith ( {
323- data : {
324- imageName,
325- testVariation : {
326- connect : {
327- id : testVariation . id ,
328- } ,
227+ expect ( saveImageMock ) . toHaveBeenCalledWith ( 'screenshot' , Buffer . from ( createTestRequestDto . imageBase64 , 'base64' ) ) ;
228+ expect ( service . getDiff ) . toHaveBeenCalledWith (
229+ baseline ,
230+ image ,
231+ createTestRequestDto . diffTollerancePercent ,
232+ testVariation . ignoreAreas
233+ ) ;
234+ expect ( getImageMock ) . toHaveBeenNthCalledWith ( 1 , testVariation . baselineName ) ;
235+ expect ( getImageMock ) . toHaveBeenNthCalledWith ( 2 , imageName ) ;
236+ expect ( testRunCreateMock ) . toHaveBeenCalledWith ( {
237+ data : {
238+ imageName,
239+ testVariation : {
240+ connect : {
241+ id : testVariation . id ,
329242 } ,
330- build : {
331- connect : {
332- id : createTestRequestDto . buildId ,
333- } ,
243+ } ,
244+ build : {
245+ connect : {
246+ id : createTestRequestDto . buildId ,
334247 } ,
335- name : testVariation . name ,
336- browser : testVariation . browser ,
337- device : testVariation . device ,
338- os : testVariation . os ,
339- viewport : testVariation . viewport ,
340- baselineName : testVariation . baselineName ,
341- ignoreAreas : testVariation . ignoreAreas ,
342- diffTollerancePercent : createTestRequestDto . diffTollerancePercent ,
343- status : TestStatus . new ,
344248 } ,
345- } ) ;
346- expect ( getDiffMock ) . toHaveBeenCalledWith ( baseline , image , testRun . diffTollerancePercent , testRun . ignoreAreas ) ;
347- expect ( saveDiffResultMock ) . toHaveBeenCalledWith ( testRun . id , diffResult ) ;
348- expect ( eventNewTestRunMock ) . toHaveBeenCalledWith ( testRunWithResult ) ;
349- expect ( result ) . toBe ( testRunWithResult ) ;
249+ name : testVariation . name ,
250+ browser : testVariation . browser ,
251+ device : testVariation . device ,
252+ os : testVariation . os ,
253+ viewport : testVariation . viewport ,
254+ baselineName : testVariation . baselineName ,
255+ ignoreAreas : testVariation . ignoreAreas ,
256+ diffTollerancePercent : createTestRequestDto . diffTollerancePercent ,
257+ status : TestStatus . new ,
258+ } ,
350259 } ) ;
260+ expect ( getDiffMock ) . toHaveBeenCalledWith ( baseline , image , testRun . diffTollerancePercent , testRun . ignoreAreas ) ;
261+ expect ( saveDiffResultMock ) . toHaveBeenCalledWith ( testRun . id , diffResult ) ;
262+ expect ( eventNewTestRunMock ) . toHaveBeenCalledWith ( testRunWithResult ) ;
263+ expect ( result ) . toBe ( testRunWithResult ) ;
351264 } ) ;
352265
353266 describe ( 'getDiff' , ( ) => {
0 commit comments