How to use jest.spyOn method in qawolf

Best JavaScript code snippet using qawolf

services.test.ts

Source:services.test.ts Github

copy

Full Screen

...119 });120 });121 describe("given user is logged in", () => {122 it("should return all services", async () => {123 jest.spyOn(passport, "authenticate").mockImplementationOnce(124 () => {125 return (126 req: Request,127 res: Response,128 next: NextFunction129 ) => {130 next();131 };132 }133 );134 jest.spyOn(ServicesService, "findAllServices")135 // @ts-ignore136 .mockReturnValueOnce([createdService]);137 const response = await supertest(app).get("/services");138 expect(response.status).toBe(200);139 expect(response.body).toEqual([createdService]);140 });141 });142 });143 describe("create new service", () => {144 describe("given the user is not logged in", () => {145 it("should return 401", async () => {146 const response = await supertest(app)147 .post("/services/create")148 .send(createServiceRequest);149 expect(response.status).toBe(401);150 });151 });152 describe("given the user is logged in", () => {153 describe("given the create service payload is valid", () => {154 it("should create service", async () => {155 jest.spyOn(passport, "authenticate").mockImplementationOnce(156 () => {157 return (158 req: Request,159 res: Response,160 next: NextFunction161 ) => {162 next();163 };164 }165 );166 jest.spyOn(ServicesService, "findServiceByName")167 //@ts-ignore168 .mockReturnValueOnce(null);169 jest.spyOn(170 ImagesService,171 "getOrCreateImageByImageIdentifier"172 )173 // @ts-ignore174 .mockReturnValueOnce(createdImage);175 jest.spyOn(ProjectsService, "findProjectByName")176 // @ts-ignore177 .mockReturnValueOnce(mockProject);178 jest.spyOn(ServicesService, "findLastUsedOrder")179 //@ts-ignore180 .mockReturnValueOnce(0);181 jest.spyOn(ServicesService, "saveService")182 // @ts-ignore183 .mockImplementationOnce((service: Service) => service);184 jest.spyOn(DockerLib, "createContainer")185 //@ts-ignore186 .mockImplementationOnce(187 async (service, image, callback) =>188 //@ts-ignore189 callback(service, createdContainer)190 );191 const response = await supertest(app)192 .post("/services/create")193 .send(createServiceRequest);194 expect(response.status).toBe(200);195 expect(response.body).toEqual(createdService);196 });197 });198 describe("given the service already exists", () => {199 it("should return a 400", async () => {200 jest.spyOn(passport, "authenticate").mockImplementationOnce(201 () => {202 return (203 req: Request,204 res: Response,205 next: NextFunction206 ) => {207 next();208 };209 }210 );211 jest.spyOn(ServicesService, "findServiceByName")212 // @ts-ignore213 .mockReturnValueOnce(createdService);214 const response = await supertest(app)215 .post("/services/create")216 .send(createServiceRequest);217 expect(response.status).toBe(400);218 });219 });220 describe("given create container throws an error", () => {221 it("should return a 400", async () => {222 jest.spyOn(passport, "authenticate").mockImplementationOnce(223 () => {224 return (225 req: Request,226 res: Response,227 next: NextFunction228 ) => {229 next();230 };231 }232 );233 jest.spyOn(ServicesService, "findServiceByName")234 //@ts-ignore235 .mockReturnValueOnce(null);236 jest.spyOn(237 ImagesService,238 "getOrCreateImageByImageIdentifier"239 )240 // @ts-ignore241 .mockReturnValueOnce(createdImage);242 jest.spyOn(ProjectsService, "findProjectByName")243 // @ts-ignore244 .mockReturnValueOnce(mockProject);245 jest.spyOn(ServicesService, "findLastUsedOrder")246 //@ts-ignore247 .mockReturnValueOnce(0);248 jest.spyOn(ServicesService, "saveService")249 // @ts-ignore250 .mockImplementationOnce((service: Service) => service);251 jest.spyOn(DockerLib, "createContainer")252 //@ts-ignore253 .mockImplementationOnce(() => {254 throw new Error();255 });256 jest.spyOn(ServicesService, "saveService")257 // @ts-ignore258 .mockImplementationOnce((service: Service) => service);259 const response = await supertest(app)260 .post("/services/create")261 .send(createServiceRequest);262 expect(response.status).toBe(500);263 });264 });265 describe("given the image does not exist", () => {266 it("should return a 500", async () => {267 jest.spyOn(passport, "authenticate").mockImplementationOnce(268 () => {269 return (270 req: Request,271 res: Response,272 next: NextFunction273 ) => {274 next();275 };276 }277 );278 jest.spyOn(ServicesService, "findServiceByName")279 //@ts-ignore280 .mockReturnValueOnce(null);281 jest.spyOn(282 ImagesService,283 "getOrCreateImageByImageIdentifier"284 )285 // @ts-ignore286 .mockReturnValueOnce(createdImage);287 jest.spyOn(ProjectsService, "findProjectByName")288 // @ts-ignore289 .mockReturnValueOnce(mockProject);290 jest.spyOn(ServicesService, "findLastUsedOrder")291 //@ts-ignore292 .mockReturnValueOnce(0);293 jest.spyOn(ServicesService, "saveService")294 // @ts-ignore295 .mockImplementationOnce((service: Service) => service);296 jest.spyOn(DockerLib, "pullImage")297 //@ts-ignore298 .mockImplementationOnce(() => {299 throw new Error("Image does not exist");300 });301 const response = await supertest(app)302 .post("/services/create")303 .send(createServiceRequest);304 expect(response.status).toBe(200);305 expect(response.body.status).toBe(ServiceStatus.ERROR);306 });307 });308 describe("given the project does not exist", () => {309 it("should return a 404", async () => {310 jest.spyOn(passport, "authenticate").mockImplementationOnce(311 () => {312 return (313 req: Request,314 res: Response,315 next: NextFunction316 ) => {317 next();318 };319 }320 );321 jest.spyOn(ServicesService, "findServiceByName")322 //@ts-ignore323 .mockReturnValueOnce(null);324 jest.spyOn(325 ImagesService,326 "getOrCreateImageByImageIdentifier"327 )328 // @ts-ignore329 .mockReturnValueOnce(createdImage);330 jest.spyOn(ProjectsService, "findProjectByName")331 // @ts-ignore332 .mockReturnValueOnce(null);333 const response = await supertest(app)334 .post("/services/create")335 .send(createServiceRequest);336 expect(response.status).toBe(404);337 });338 });339 describe("given the create service payload is invalid", () => {340 it("should return a 400", async () => {341 jest.spyOn(passport, "authenticate").mockImplementationOnce(342 () => {343 return (344 req: Request,345 res: Response,346 next: NextFunction347 ) => {348 next();349 };350 }351 );352 const response = await supertest(app)353 .post("/services/create")354 .send(invalidCreateServiceRequest);355 expect(response.status).toBe(400);356 });357 });358 });359 });360 describe("start service", () => {361 describe("given the user is not logged in", () => {362 it("should return 401", async () => {363 const response = await supertest(app).put(364 "/services/httpd/start"365 );366 expect(response.status).toBe(401);367 });368 });369 describe("given the user is logged in", () => {370 describe("given the service does not exist", () => {371 it("it should return 404", async () => {372 jest.spyOn(passport, "authenticate").mockImplementationOnce(373 () => {374 return (375 req: Request,376 res: Response,377 next: NextFunction378 ) => {379 next();380 };381 }382 );383 jest.spyOn(384 ServicesService,385 "findServiceByName"386 ).mockImplementationOnce(async () => {387 return null;388 });389 const response = await supertest(app).put(390 "/services/httpd/start"391 );392 expect(response.status).toBe(404);393 });394 });395 describe("given the service exists and it has CREATED status", () => {396 it("it should return the service with RUNNING status", async () => {397 jest.spyOn(passport, "authenticate").mockImplementationOnce(398 () => {399 return (400 req: Request,401 res: Response,402 next: NextFunction403 ) => {404 next();405 };406 }407 );408 jest.spyOn(409 ServicesService,410 "findServiceByName"411 ).mockImplementationOnce(async () => {412 const foundService = createdService;413 foundService.status = ServiceStatus.CREATED;414 return foundService;415 });416 jest.spyOn(417 DockerLib,418 "startContainer"419 ).mockImplementationOnce(async () => {420 return Promise.resolve();421 });422 jest.spyOn(423 ServicesService,424 "saveService"425 ).mockImplementationOnce(426 async (service: Service) => service427 );428 const response = await supertest(app).put(429 "/services/httpd/start"430 );431 expect(response.status).toBe(200);432 expect(response.body.status).toBe(ServiceStatus.RUNNING);433 });434 describe("given the container cannot be found", () => {435 it("it should return a 400", async () => {436 jest.spyOn(437 passport,438 "authenticate"439 ).mockImplementationOnce(() => {440 return (441 req: Request,442 res: Response,443 next: NextFunction444 ) => {445 next();446 };447 });448 jest.spyOn(449 ServicesService,450 "findServiceByName"451 ).mockImplementationOnce(async () => {452 const foundService = createdService;453 foundService.status = ServiceStatus.CREATED;454 return foundService;455 });456 jest.spyOn(457 DockerLib,458 "startContainer"459 ).mockImplementationOnce(async () => {460 throw new Error("Container not found");461 });462 jest.spyOn(463 ServicesService,464 "saveService"465 ).mockImplementationOnce(466 async (service: Service) => service467 );468 const response = await supertest(app).put(469 "/services/httpd/start"470 );471 expect(response.status).toBe(500);472 });473 });474 });475 describe("given the service exists and it has RUNNING status", () => {476 it("it should return 400", async () => {477 jest.spyOn(passport, "authenticate").mockImplementationOnce(478 () => {479 return (480 req: Request,481 res: Response,482 next: NextFunction483 ) => {484 next();485 };486 }487 );488 jest.spyOn(489 ServicesService,490 "findServiceByName"491 ).mockImplementationOnce(async () => {492 const foundService = createdService;493 foundService.status = ServiceStatus.RUNNING;494 return foundService;495 });496 const response = await supertest(app).put(497 "/services/httpd/start"498 );499 expect(response.status).toBe(400);500 });501 });502 describe("given the service exists and it has ERROR status", () => {503 it("it should return 400", async () => {504 jest.spyOn(passport, "authenticate").mockImplementationOnce(505 () => {506 return (507 req: Request,508 res: Response,509 next: NextFunction510 ) => {511 next();512 };513 }514 );515 jest.spyOn(516 ServicesService,517 "findServiceByName"518 ).mockImplementationOnce(async () => {519 const foundService = createdService;520 foundService.status = ServiceStatus.ERROR;521 return foundService;522 });523 const response = await supertest(app).put(524 "/services/httpd/start"525 );526 expect(response.status).toBe(400);527 });528 });529 describe("given the service exists and it has PULLING status", () => {530 it("it should return 400", async () => {531 jest.spyOn(passport, "authenticate").mockImplementationOnce(532 () => {533 return (534 req: Request,535 res: Response,536 next: NextFunction537 ) => {538 next();539 };540 }541 );542 jest.spyOn(543 ServicesService,544 "findServiceByName"545 ).mockImplementationOnce(async () => {546 const foundService = createdService;547 foundService.status = ServiceStatus.PULLING;548 return foundService;549 });550 const response = await supertest(app).put(551 "/services/httpd/start"552 );553 expect(response.status).toBe(400);554 });555 });556 });557 });558 describe("update service", () => {559 describe("given the user is not logged in", () => {560 it("should return 401", async () => {561 const response = await supertest(app)562 .put("/services/httpd/update")563 .send(emptyUpdateRequest);564 expect(response.status).toBe(401);565 });566 });567 describe("given the user is logged in", () => {568 describe("given an empty request", () => {569 it("should return 400", async () => {570 jest.spyOn(passport, "authenticate").mockImplementationOnce(571 () => {572 return (573 req: Request,574 res: Response,575 next: NextFunction576 ) => {577 next();578 };579 }580 );581 const response = await supertest(app)582 .put("/services/httpd/update")583 .send(emptyUpdateRequest);584 expect(response.status).toBe(400);585 });586 });587 describe("given an invalid request", () => {588 it("should return 400", async () => {589 jest.spyOn(passport, "authenticate").mockImplementationOnce(590 () => {591 return (592 req: Request,593 res: Response,594 next: NextFunction595 ) => {596 next();597 };598 }599 );600 const response = await supertest(app)601 .put("/services/httpd/update")602 .send(invalidUpdateRequest);603 expect(response.status).toBe(400);604 });605 });606 describe("given the service does not exist", () => {607 it("should return 404", async () => {608 jest.spyOn(passport, "authenticate").mockImplementationOnce(609 () => {610 return (611 req: Request,612 res: Response,613 next: NextFunction614 ) => {615 next();616 };617 }618 );619 jest.spyOn(620 ServicesService,621 "findServiceByName"622 ).mockImplementationOnce(async () => {623 return null;624 });625 const response = await supertest(app)626 .put("/services/httpd/update")627 .send(updateAllRequest);628 expect(response.status).toBe(404);629 });630 });631 describe("given the service exists and it has PULLING status", () => {632 it("should return 400", async () => {633 jest.spyOn(passport, "authenticate").mockImplementationOnce(634 () => {635 return (636 req: Request,637 res: Response,638 next: NextFunction639 ) => {640 next();641 };642 }643 );644 jest.spyOn(645 ServicesService,646 "findServiceByName"647 ).mockImplementationOnce(async () => {648 const foundService = createdService;649 foundService.status = ServiceStatus.PULLING;650 return foundService;651 });652 const response = await supertest(app)653 .put("/services/httpd/update")654 .send(updateAllRequest);655 expect(response.status).toBe(400);656 });657 });658 describe("given the service exists and its an update HOSTS request", () => {659 it("should return the service with updated hosts", async () => {660 jest.spyOn(passport, "authenticate").mockImplementationOnce(661 () => {662 return (663 req: Request,664 res: Response,665 next: NextFunction666 ) => {667 next();668 };669 }670 );671 jest.spyOn(672 ServicesService,673 "findServiceByName"674 ).mockImplementationOnce(async () => {675 const foundService = createdService;676 foundService.status = ServiceStatus.CREATED;677 return foundService;678 });679 jest.spyOn(680 ImagesService,681 "getOrCreateImageByImageIdentifier"682 )683 // @ts-ignore684 .mockReturnValueOnce(createdImage);685 jest.spyOn(686 DockerLib,687 "deleteContainer"688 ).mockImplementationOnce(async () => {689 return Promise.resolve();690 });691 jest.spyOn(ServicesService, "saveService")692 // @ts-ignore693 .mockImplementationOnce((service: Service) => service);694 jest.spyOn(DockerLib, "createContainer")695 //@ts-ignore696 .mockImplementationOnce(697 async (service, image, callback) =>698 //@ts-ignore699 callback(service, postUpdateContainer)700 );701 const response = await supertest(app)702 .put("/services/httpd/update")703 .send(updateHostsRequest);704 expect(response.status).toBe(200);705 expect(response.body.hosts).toStrictEqual(706 updateHostsRequest.hosts707 );708 });709 });710 describe("given the service exists and its an update REDIRECTS request", () => {711 it("should return the service with updated redirects", async () => {712 jest.spyOn(passport, "authenticate").mockImplementationOnce(713 () => {714 return (715 req: Request,716 res: Response,717 next: NextFunction718 ) => {719 next();720 };721 }722 );723 jest.spyOn(724 ServicesService,725 "findServiceByName"726 ).mockImplementationOnce(async () => {727 const foundService = createdService;728 foundService.status = ServiceStatus.CREATED;729 return foundService;730 });731 jest.spyOn(732 ImagesService,733 "getOrCreateImageByImageIdentifier"734 )735 // @ts-ignore736 .mockReturnValueOnce(createdImage);737 jest.spyOn(738 DockerLib,739 "deleteContainer"740 ).mockImplementationOnce(async () => {741 return Promise.resolve();742 });743 jest.spyOn(ServicesService, "saveService")744 // @ts-ignore745 .mockImplementationOnce((service: Service) => service);746 jest.spyOn(DockerLib, "createContainer")747 //@ts-ignore748 .mockImplementationOnce(749 async (service, image, callback) =>750 //@ts-ignore751 callback(service, postUpdateContainer)752 );753 const response = await supertest(app)754 .put("/services/httpd/update")755 .send(updateRedirectsRequest);756 expect(response.status).toBe(200);757 expect(response.body.redirects).toStrictEqual(758 updateRedirectsRequest.redirects759 );760 });761 });762 describe("given the service exists and its an update ENVIRONMENT VARIABLES request", () => {763 it("should return the service with updated environment variables", async () => {764 jest.spyOn(passport, "authenticate").mockImplementationOnce(765 () => {766 return (767 req: Request,768 res: Response,769 next: NextFunction770 ) => {771 next();772 };773 }774 );775 jest.spyOn(776 ServicesService,777 "findServiceByName"778 ).mockImplementationOnce(async () => {779 const foundService = createdService;780 foundService.status = ServiceStatus.CREATED;781 return foundService;782 });783 jest.spyOn(784 ImagesService,785 "getOrCreateImageByImageIdentifier"786 )787 // @ts-ignore788 .mockReturnValueOnce(createdImage);789 jest.spyOn(790 DockerLib,791 "deleteContainer"792 ).mockImplementationOnce(async () => {793 return Promise.resolve();794 });795 jest.spyOn(ServicesService, "saveService")796 // @ts-ignore797 .mockImplementationOnce((service: Service) => service);798 jest.spyOn(DockerLib, "createContainer")799 //@ts-ignore800 .mockImplementationOnce(801 async (service, image, callback) =>802 //@ts-ignore803 callback(service, postUpdateContainer)804 );805 const response = await supertest(app)806 .put("/services/httpd/update")807 .send(updateEnvironmentVariablesRequest);808 expect(response.status).toBe(200);809 expect(response.body.environmentVariables).toStrictEqual(810 updateEnvironmentVariablesRequest.environmentVariables811 );812 });813 });814 describe("given the service exists and its an update ALL request", () => {815 it("should return the service with updated ALL", async () => {816 jest.spyOn(passport, "authenticate").mockImplementationOnce(817 () => {818 return (819 req: Request,820 res: Response,821 next: NextFunction822 ) => {823 next();824 };825 }826 );827 jest.spyOn(828 ServicesService,829 "findServiceByName"830 ).mockImplementationOnce(async () => {831 const foundService = createdService;832 foundService.status = ServiceStatus.CREATED;833 return foundService;834 });835 jest.spyOn(836 ImagesService,837 "getOrCreateImageByImageIdentifier"838 )839 // @ts-ignore840 .mockReturnValueOnce(createdImage);841 jest.spyOn(842 DockerLib,843 "deleteContainer"844 ).mockImplementationOnce(async () => {845 return Promise.resolve();846 });847 jest.spyOn(ServicesService, "saveService")848 // @ts-ignore849 .mockImplementationOnce((service: Service) => service);850 jest.spyOn(DockerLib, "createContainer")851 //@ts-ignore852 .mockImplementationOnce(853 async (service, image, callback) =>854 //@ts-ignore855 callback(service, postUpdateContainer)856 );857 const response = await supertest(app)858 .put("/services/httpd/update")859 .send(updateAllRequest);860 expect(response.status).toBe(200);861 expect(response.body.hosts).toStrictEqual(862 updateAllRequest.hosts863 );864 expect(response.body.redirects).toStrictEqual(865 updateAllRequest.redirects866 );867 expect(response.body.environmentVariables).toStrictEqual(868 updateAllRequest.environmentVariables869 );870 });871 describe("given the container does not exist", () => {872 it("should return a 400", async () => {873 jest.spyOn(874 passport,875 "authenticate"876 ).mockImplementationOnce(() => {877 return (878 req: Request,879 res: Response,880 next: NextFunction881 ) => {882 next();883 };884 });885 jest.spyOn(886 ServicesService,887 "findServiceByName"888 ).mockImplementationOnce(async () => {889 const foundService = createdService;890 foundService.status = ServiceStatus.CREATED;891 return foundService;892 });893 jest.spyOn(894 ImagesService,895 "getOrCreateImageByImageIdentifier"896 )897 // @ts-ignore898 .mockReturnValueOnce(createdImage);899 jest.spyOn(900 DockerLib,901 "deleteContainer"902 ).mockImplementationOnce(async () => {903 throw new Error("Container does not exist");904 });905 jest.spyOn(906 ServicesService,907 "saveService"908 ).mockImplementationOnce(909 // @ts-ignore910 (service: Service) => service911 );912 jest.spyOn(DockerLib, "createContainer")913 //@ts-ignore914 .mockImplementationOnce(915 async (service, image, callback) =>916 //@ts-ignore917 callback(service, postUpdateContainer)918 );919 const response = await supertest(app)920 .put("/services/httpd/update")921 .send(updateAllRequest);922 expect(response.status).toBe(500);923 });924 });925 });926 });927 });928 describe("stop service", () => {929 describe("given the user is not logged in", () => {930 it("should return 401", async () => {931 const response = await supertest(app).put(932 "/services/httpd/stop"933 );934 expect(response.status).toBe(401);935 });936 });937 describe("given the user is logged in", () => {938 describe("given the service does not exist", () => {939 it("it should return 404", async () => {940 jest.spyOn(passport, "authenticate").mockImplementationOnce(941 () => {942 return (943 req: Request,944 res: Response,945 next: NextFunction946 ) => {947 next();948 };949 }950 );951 jest.spyOn(952 ServicesService,953 "findServiceByName"954 ).mockImplementationOnce(async () => {955 return null;956 });957 const response = await supertest(app).put(958 "/services/httpd/stop"959 );960 expect(response.status).toBe(404);961 });962 });963 describe("given the service exists and it has RUNNING status", () => {964 it("it should return the service with STOPPED status", async () => {965 jest.spyOn(passport, "authenticate").mockImplementationOnce(966 () => {967 return (968 req: Request,969 res: Response,970 next: NextFunction971 ) => {972 next();973 };974 }975 );976 jest.spyOn(977 ServicesService,978 "findServiceByName"979 ).mockImplementationOnce(async () => {980 const foundService = createdService;981 foundService.status = ServiceStatus.RUNNING;982 return foundService;983 });984 jest.spyOn(985 DockerLib,986 "stopContainer"987 ).mockImplementationOnce(async () => {988 return Promise.resolve();989 });990 jest.spyOn(991 ServicesService,992 "saveService"993 ).mockImplementationOnce(994 async (service: Service) => service995 );996 const response = await supertest(app).put(997 "/services/httpd/stop"998 );999 expect(response.status).toBe(200);1000 expect(response.body.status).toBe(ServiceStatus.STOPPED);1001 });1002 describe("given the container cannot be found", () => {1003 it("it should return a 400", async () => {1004 jest.spyOn(1005 passport,1006 "authenticate"1007 ).mockImplementationOnce(() => {1008 return (1009 req: Request,1010 res: Response,1011 next: NextFunction1012 ) => {1013 next();1014 };1015 });1016 jest.spyOn(1017 ServicesService,1018 "findServiceByName"1019 ).mockImplementationOnce(async () => {1020 const foundService = createdService;1021 foundService.status = ServiceStatus.RUNNING;1022 return foundService;1023 });1024 jest.spyOn(1025 DockerLib,1026 "stopContainer"1027 ).mockImplementationOnce(async () => {1028 throw new Error("Container not found");1029 });1030 jest.spyOn(1031 ServicesService,1032 "saveService"1033 ).mockImplementationOnce(1034 async (service: Service) => service1035 );1036 const response = await supertest(app).put(1037 "/services/httpd/stop"1038 );1039 expect(response.status).toBe(500);1040 });1041 });1042 });1043 describe("given the service exists and it has STOPPED status", () => {1044 it("it should return 400", async () => {1045 jest.spyOn(passport, "authenticate").mockImplementationOnce(1046 () => {1047 return (1048 req: Request,1049 res: Response,1050 next: NextFunction1051 ) => {1052 next();1053 };1054 }1055 );1056 jest.spyOn(1057 ServicesService,1058 "findServiceByName"1059 ).mockImplementationOnce(async () => {1060 const foundService = createdService;1061 foundService.status = ServiceStatus.STOPPED;1062 return foundService;1063 });1064 const response = await supertest(app).put(1065 "/services/httpd/stop"1066 );1067 expect(response.status).toBe(400);1068 });1069 });1070 describe("given the service exists and it has ERROR status", () => {1071 it("it should return 400", async () => {1072 jest.spyOn(passport, "authenticate").mockImplementationOnce(1073 () => {1074 return (1075 req: Request,1076 res: Response,1077 next: NextFunction1078 ) => {1079 next();1080 };1081 }1082 );1083 jest.spyOn(1084 ServicesService,1085 "findServiceByName"1086 ).mockImplementationOnce(async () => {1087 const foundService = createdService;1088 foundService.status = ServiceStatus.ERROR;1089 return foundService;1090 });1091 const response = await supertest(app).put(1092 "/services/httpd/stop"1093 );1094 expect(response.status).toBe(400);1095 });1096 });1097 describe("given the service exists and it has PULLING status", () => {1098 it("it should return 400", async () => {1099 jest.spyOn(passport, "authenticate").mockImplementationOnce(1100 () => {1101 return (1102 req: Request,1103 res: Response,1104 next: NextFunction1105 ) => {1106 next();1107 };1108 }1109 );1110 jest.spyOn(1111 ServicesService,1112 "findServiceByName"1113 ).mockImplementationOnce(async () => {1114 const foundService = createdService;1115 foundService.status = ServiceStatus.PULLING;1116 return foundService;1117 });1118 const response = await supertest(app).put(1119 "/services/httpd/stop"1120 );1121 expect(response.status).toBe(400);1122 });1123 });1124 });1125 });1126 describe("delete service", () => {1127 describe("given the user is not logged in", () => {1128 it("should return 401", async () => {1129 const response = await supertest(app).delete(1130 "/services/httpd/delete"1131 );1132 expect(response.status).toBe(401);1133 });1134 });1135 describe("given the user is logged in", () => {1136 describe("given the service does not exist", () => {1137 it("it should return 404", async () => {1138 jest.spyOn(passport, "authenticate").mockImplementationOnce(1139 () => {1140 return (1141 req: Request,1142 res: Response,1143 next: NextFunction1144 ) => {1145 next();1146 };1147 }1148 );1149 jest.spyOn(1150 ServicesService,1151 "findServiceByName"1152 ).mockImplementationOnce(async () => {1153 return null;1154 });1155 const response = await supertest(app).delete(1156 "/services/httpd/delete"1157 );1158 expect(response.status).toBe(404);1159 });1160 });1161 describe("given the service exists and it has CREATED or STOPPED status", () => {1162 it("it should return 200", async () => {1163 jest.spyOn(passport, "authenticate").mockImplementationOnce(1164 () => {1165 return (1166 req: Request,1167 res: Response,1168 next: NextFunction1169 ) => {1170 next();1171 };1172 }1173 );1174 jest.spyOn(1175 ServicesService,1176 "findServiceByName"1177 ).mockImplementationOnce(async () => {1178 const foundService = createdService;1179 foundService.status = ServiceStatus.CREATED;1180 return foundService;1181 });1182 jest.spyOn(1183 DockerLib,1184 "deleteContainer"1185 ).mockImplementationOnce(async () => {1186 return Promise.resolve();1187 });1188 jest.spyOn(1189 ServicesService,1190 "deleteServiceByName"1191 ).mockImplementationOnce(async () => {1192 return Promise.resolve();1193 });1194 const response = await supertest(app).delete(1195 "/services/httpd/delete"1196 );1197 expect(response.status).toBe(200);1198 });1199 describe("given the container cannot be found", () => {1200 it("it should return a 400", async () => {1201 jest.spyOn(1202 passport,1203 "authenticate"1204 ).mockImplementationOnce(() => {1205 return (1206 req: Request,1207 res: Response,1208 next: NextFunction1209 ) => {1210 next();1211 };1212 });1213 jest.spyOn(1214 ServicesService,1215 "findServiceByName"1216 ).mockImplementationOnce(async () => {1217 const foundService = createdService;1218 foundService.status = ServiceStatus.CREATED;1219 return foundService;1220 });1221 jest.spyOn(1222 DockerLib,1223 "deleteContainer"1224 ).mockImplementationOnce(async () => {1225 throw new Error("Container not found");1226 });1227 const response = await supertest(app).delete(1228 "/services/httpd/delete"1229 );1230 expect(response.status).toBe(500);1231 });1232 });1233 });1234 describe("given the service exists and it has RUNNING status", () => {1235 it("it should return 200", async () => {1236 jest.spyOn(passport, "authenticate").mockImplementationOnce(1237 () => {1238 return (1239 req: Request,1240 res: Response,1241 next: NextFunction1242 ) => {1243 next();1244 };1245 }1246 );1247 jest.spyOn(1248 ServicesService,1249 "findServiceByName"1250 ).mockImplementationOnce(async () => {1251 const foundService = createdService;1252 foundService.status = ServiceStatus.RUNNING;1253 return foundService;1254 });1255 const stopContainerMock = jest1256 .spyOn(DockerLib, "stopContainer")1257 .mockImplementationOnce(async () => {1258 return Promise.resolve();1259 });1260 jest.spyOn(1261 DockerLib,1262 "deleteContainer"1263 ).mockImplementationOnce(async (service: Service) => {1264 await DockerLib.stopContainer(service);1265 return Promise.resolve();1266 });1267 jest.spyOn(1268 ServicesService,1269 "deleteServiceByName"1270 ).mockImplementationOnce(async () => {1271 return Promise.resolve();1272 });1273 const response = await supertest(app).delete(1274 "/services/httpd/delete"1275 );1276 expect(response.status).toBe(200);1277 expect(stopContainerMock).toHaveBeenCalledTimes(1);1278 });1279 });1280 describe("given the service exists and it has PULLING status", () => {1281 it("it should return 400", async () => {1282 jest.spyOn(passport, "authenticate").mockImplementationOnce(1283 () => {1284 return (1285 req: Request,1286 res: Response,1287 next: NextFunction1288 ) => {1289 next();1290 };1291 }1292 );1293 jest.spyOn(1294 ServicesService,1295 "findServiceByName"1296 ).mockImplementationOnce(async () => {1297 const foundService = createdService;1298 foundService.status = ServiceStatus.PULLING;1299 return foundService;1300 });1301 const response = await supertest(app).delete(1302 "/services/httpd/delete"1303 );1304 expect(response.status).toBe(400);1305 });1306 });1307 });1308 });1309 describe("update services ordering", () => {1310 describe("given the user is not logged in", () => {1311 it("should return 401", async () => {1312 const response = await supertest(app).put("/services/order");1313 expect(response.status).toBe(401);1314 });1315 });1316 describe("given the user is logged in", () => {1317 describe("given an invalid request", () => {1318 it("should return 400", async () => {1319 jest.spyOn(passport, "authenticate").mockImplementationOnce(1320 () => {1321 return (1322 req: Request,1323 res: Response,1324 next: NextFunction1325 ) => {1326 next();1327 };1328 }1329 );1330 const response = await supertest(app)1331 .put("/services/order")1332 .send({1333 service: [],1334 });1335 expect(response.status).toBe(400);1336 });1337 });1338 describe("given something throws", () => {1339 it("should return 500", async () => {1340 jest.spyOn(passport, "authenticate").mockImplementationOnce(1341 () => {1342 return (1343 req: Request,1344 res: Response,1345 next: NextFunction1346 ) => {1347 next();1348 };1349 }1350 );1351 const findServiceByNameMock = jest1352 .spyOn(ServicesService, "findServiceByName")1353 .mockImplementation(async () => {1354 throw new Error("Something went wrong");1355 });1356 jest.spyOn(ServicesService, "saveService")1357 // @ts-ignore1358 .mockImplementationOnce((service: Service) => service);1359 const response = await supertest(app)1360 .put("/services/order")1361 .send({1362 services: [{ name: "httpd", order: 2 }],1363 });1364 expect(response.status).toBe(500);1365 findServiceByNameMock.mockClear();1366 });1367 });1368 describe("given one of the services is not found", () => {1369 it("should return 404", async () => {1370 jest.spyOn(passport, "authenticate").mockImplementationOnce(1371 () => {1372 return (1373 req: Request,1374 res: Response,1375 next: NextFunction1376 ) => {1377 next();1378 };1379 }1380 );1381 const findServiceByNameMock = jest1382 .spyOn(ServicesService, "findServiceByName")1383 .mockImplementation(async (name: string) => {1384 if (name === "httpd") {1385 return Promise.resolve(createdService);1386 }1387 return Promise.resolve(null);1388 });1389 const saveServiceMock = jest1390 .spyOn(ServicesService, "saveService")1391 // @ts-ignore1392 .mockImplementationOnce((service: Service) => service);1393 const response = await supertest(app)1394 .put("/services/order")1395 .send({1396 services: [1397 { name: "httpd", order: 2 },1398 { name: "notfound", order: 1 },1399 ],1400 });1401 expect(response.status).toBe(404);1402 expect(saveServiceMock).toHaveBeenCalledTimes(0);1403 findServiceByNameMock.mockClear();1404 });1405 });1406 describe("given all the services are found", () => {1407 it("should return 200", async () => {1408 jest.spyOn(passport, "authenticate").mockImplementationOnce(1409 () => {1410 return (1411 req: Request,1412 res: Response,1413 next: NextFunction1414 ) => {1415 next();1416 };1417 }1418 );1419 const findServiceByNameMock = jest1420 .spyOn(ServicesService, "findServiceByName")1421 .mockImplementation(async (name: string) => {1422 if (name === "httpd") {...

Full Screen

Full Screen

helm-util.test.ts

Source:helm-util.test.ts Github

copy

Full Screen

...7import * as io from '@actions/io';89describe('This is a placeholder for intial test cases, to be removed', () => {10 test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {11 jest.spyOn(os, 'type').mockReturnValue('Linux');12 const helmLinuxUrl = 'https://get.helm.sh/helm-v3.2.1-linux-amd64.zip'1314 expect(helmUtil.getHelmDownloadURL('v3.2.1')).toBe(helmLinuxUrl);15 expect(os.type).toBeCalled(); 16 });1718 test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {19 jest.spyOn(os, 'type').mockReturnValue('Darwin');20 const helmDarwinUrl = 'https://get.helm.sh/helm-v3.2.1-darwin-amd64.zip'2122 expect(helmUtil.getHelmDownloadURL('v3.2.1')).toBe(helmDarwinUrl);23 expect(os.type).toBeCalled(); 24 });2526 test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {27 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');2829 const helmWindowsUrl = 'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'30 expect(helmUtil.getHelmDownloadURL('v3.2.1')).toBe(helmWindowsUrl);31 expect(os.type).toBeCalled(); 32 });3334 test('walkSync() - return path to the all files matching fileToFind in dir', () => {35 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {36 if (file == 'mainFolder') return ['file1' as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent];37 if (file == path.join('mainFolder', 'folder1')) return ['file11' as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent];38 if (file == path.join('mainFolder', 'folder2')) return ['file21' as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent];39 });40 jest.spyOn(core, 'debug').mockImplementation();41 jest.spyOn(fs, 'statSync').mockImplementation((file) => {42 const isDirectory = (file as string).toLowerCase().indexOf('file') == -1 ? true: false43 return { isDirectory: () => isDirectory } as fs.Stats;44 });4546 expect(helmUtil.walkSync('mainFolder', null, 'file21')).toEqual([path.join('mainFolder', 'folder2', 'file21')]);47 expect(fs.readdirSync).toBeCalledTimes(3);48 expect(fs.statSync).toBeCalledTimes(8);49 });5051 test('walkSync() - return empty array if no file with name fileToFind exists', () => {52 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {53 if (file == 'mainFolder') return ['file1' as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent];54 if (file == path.join('mainFolder', 'folder1')) return ['file11' as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent];55 if (file == path.join('mainFolder', 'folder2')) return ['file21' as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent];56 });57 jest.spyOn(core, 'debug').mockImplementation();58 jest.spyOn(fs, 'statSync').mockImplementation((file) => {59 const isDirectory = (file as string).toLowerCase().indexOf('file') == -1 ? true: false60 return { isDirectory: () => isDirectory } as fs.Stats;61 });6263 expect(helmUtil.walkSync('mainFolder', null, 'helm.exe')).toEqual([]);64 expect(fs.readdirSync).toBeCalledTimes(3);65 expect(fs.statSync).toBeCalledTimes(8);66 });6768 test('getStableHelmVersion() - download stable version file, read version and return it', async () => {69 jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');70 const response = JSON.stringify({71 'tag_name': 'v4.0.0'72 });73 jest.spyOn(fs, 'readFileSync').mockReturnValue(response);7475 expect(await helmUtil.getStableHelmVersion()).toBe('v4.0.0');76 expect(toolCache.downloadTool).toBeCalled();77 expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');78 });7980 test('getStableHelmVersion() - return default version if stable version file is empty', async () => {81 jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');82 const response = JSON.stringify({});83 jest.spyOn(fs, 'readFileSync').mockReturnValue(response);8485 expect(await helmUtil.getStableHelmVersion()).toBe('v2.14.1');86 expect(toolCache.downloadTool).toBeCalled();87 expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');88 });8990 test('getStableHelmVersion() - return default version if stable version file download fails', async () => {91 jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => { throw 'Error!!'});9293 expect(await helmUtil.getStableHelmVersion()).toBe('v2.14.1');94 expect(toolCache.downloadTool).toBeCalled();95 });9697 test('downloadHelm() - throw error when unable to download', async () => {98 jest.spyOn(toolCache, 'find').mockReturnValue('');99 jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => { throw 'Unable to download.'});100 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');101 jest.spyOn(core, 'debug').mockImplementation();102103 await expect(helmUtil.downloadHelm('v2.14.1')).rejects.toThrow('Failed to download Helm from location https://get.helm.sh/helm-v2.14.1-windows-amd64.zip. Error: Unable to download.');104 expect(toolCache.find).toBeCalledWith('helm', 'v2.14.1');105 expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v2.14.1-windows-amd64.zip');106 });107108 test('downloadHelm() - find helm executable in toolCache and return path', async () => {109 jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir');110 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');111 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);112 jest.spyOn(fs, 'statSync').mockImplementation((file) => {113 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true114 return { isDirectory: () => isDirectory } as fs.Stats;115 });116 jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});117 jest.spyOn(core, 'debug').mockImplementation();118119 expect(await helmUtil.downloadHelm('v2.14.1')).toBe(path.join('pathToCachedDir', 'helm.exe'));120 expect(toolCache.find).toBeCalledWith('helm', 'v2.14.1');121 expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedDir', 'helm.exe'), '777');122 });123124 test('downloadHelm() - throw error if helm executable not found in cache', async () => {125 jest.spyOn(toolCache, 'find').mockReturnValue('');126 jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');127 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');128 jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});129 jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');130 jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');131 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => []);132 jest.spyOn(fs, 'statSync').mockImplementation((file) => {133 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true134 return { isDirectory: () => isDirectory } as fs.Stats;135 });136137 await expect(helmUtil.downloadHelm('v2.14.1')).rejects.toThrow('Helm executable not found in path pathToCachedDir');138 expect(toolCache.find).toBeCalledWith('helm', 'v2.14.1');139 expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v2.14.1-windows-amd64.zip');140 expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');141 expect(toolCache.extractZip).toBeCalledWith('pathToTool');142 });143144 test('downloadHelm() - get stable version of helm, download and return path', async () => {145 jest.spyOn(toolCache, 'find').mockReturnValue('');146 jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');147 const response = JSON.stringify({148 'tag_name': 'v4.0.0'149 });150 jest.spyOn(fs, 'readFileSync').mockReturnValue(response);151 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');152 jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});153 jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');154 jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');155 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);156 jest.spyOn(fs, 'statSync').mockImplementation((file) => {157 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true158 return { isDirectory: () => isDirectory } as fs.Stats;159 });160161 expect(await helmUtil.downloadHelm(null)).toBe(path.join('pathToCachedDir', 'helm.exe'));162 expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0');163 expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v4.0.0-windows-amd64.zip');164 expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');165 expect(toolCache.extractZip).toBeCalledWith('pathToTool');166 expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedDir', 'helm.exe'), '777');167 });168169 test('installHelm() - download specified version helm and return its path', async () => {170 jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir');171 jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => { throw 'Unable to download'});172 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');173 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);174 jest.spyOn(fs, 'statSync').mockImplementation((file) => {175 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true176 return { isDirectory: () => isDirectory } as fs.Stats;177 });178 jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});179 jest.spyOn(core, 'debug').mockImplementation();180181 expect(await helmUtil.installHelm('v2.14.1')).toBe(path.join('pathToCachedDir', 'helm.exe'));182 });183184 test('installHelm() - get latest version of helm and return its path', async () => {185 jest.spyOn(toolCache, 'find').mockReturnValue('');186 jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');187 const response = JSON.stringify({188 'tag_name': 'v4.0.0'189 });190 jest.spyOn(fs, 'readFileSync').mockReturnValue(response);191 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');192 jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});193 jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');194 jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');195 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);196 jest.spyOn(fs, 'statSync').mockImplementation((file) => {197 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true198 return { isDirectory: () => isDirectory } as fs.Stats;199 });200 jest.spyOn(core, 'debug').mockImplementation();201202 expect(await helmUtil.installHelm('latest')).toBe(path.join('pathToCachedDir', 'helm.exe'));203 });204205 test('getHelmPath() - download helm and return its path', async () => {206 jest.spyOn(core, 'getInput').mockReturnValue('v2.14.1');207 jest.spyOn(toolCache, 'find').mockReturnValueOnce('').mockReturnValueOnce('pathToCachedDir');208 jest.spyOn(os, 'type').mockReturnValue('Windows_NT');209 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);210 jest.spyOn(fs, 'statSync').mockImplementation((file) => {211 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true212 return { isDirectory: () => isDirectory } as fs.Stats;213 });214 jest.spyOn(fs, 'chmodSync').mockImplementation();215216 expect(await helmUtil.getHelmPath()).toBe(path.join('pathToCachedDir', 'helm.exe'));217 expect(toolCache.find).toBeCalledWith('helm', 'v2.14.1');218 });219220 test('getHelmPath() - return helm From toolCache', async () => {221 jest.spyOn(core, 'getInput').mockReturnValue('v2.14.1');222 jest.spyOn(toolCache, 'find').mockReturnValue('pathToTool');223224 expect(await helmUtil.getHelmPath()).toBe('pathToTool');225 expect(toolCache.find).toBeCalledWith('helm', 'v2.14.1');226 });227228 test('getHelmPath() - return path any version helm executable if version input not specified', async () => {229 jest.spyOn(core, 'getInput').mockReturnValue('');230 jest.spyOn(io, 'which').mockResolvedValue('pathToHelm');231232 expect(await helmUtil.getHelmPath()).toBe('pathToHelm');233 expect(core.getInput).toBeCalledWith('helm-version', {"required": false});234 expect(io.which).toBeCalledWith('helm', false);235 });236237 test('getHelmPath() - return path to any version helm from tool cache', async () => {238 jest.spyOn(core, 'getInput').mockReturnValue('');239 jest.spyOn(io, 'which').mockResolvedValue('');240 jest.spyOn(toolCache, 'findAllVersions').mockReturnValue(['pathToHelm']);241242 expect(await helmUtil.getHelmPath()).toBe(path.join('pathToTool', 'helm.exe'));243 expect(toolCache.findAllVersions).toBeCalledWith('helm');244 expect(core.getInput).toBeCalledWith('helm-version', {"required": false});245 expect(io.which).toBeCalledWith('helm', false);246 });247248 test('installHelm() - throw error when version input not specified and no executable found', async () => {249 jest.spyOn(core, 'getInput').mockReturnValue('');250 jest.spyOn(io, 'which').mockResolvedValue('');251 jest.spyOn(toolCache, 'findAllVersions').mockReturnValue([]);252253 await expect(helmUtil.getHelmPath()).rejects.toThrow('helm is not installed, either add setup-helm action or provide "helm-version" input to download helm');254 expect(toolCache.findAllVersions).toBeCalledWith('helm');255 expect(core.getInput).toBeCalledWith('helm-version', {"required": false});256 expect(io.which).toBeCalledWith('helm', false);257 });258259 test('findHelm() - change access permissions and find the helm in given directory', () => {260 jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);261 jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});262 jest.spyOn(fs, 'statSync').mockImplementation((file) => {263 const isDirectory = (file as string).indexOf('folder') == -1 ? false: true264 return { isDirectory: () => isDirectory } as fs.Stats;265 });266 267 expect(helmUtil.findHelm('mainFolder')).toBe(path.join('mainFolder', 'helm.exe'));268 expect(fs.chmodSync).toBeCalledWith('mainFolder', '777');269 expect(fs.readdirSync).toBeCalledWith('mainFolder');270 expect(fs.statSync).toBeCalledWith(path.join('mainFolder', 'helm.exe'));271 }); ...

Full Screen

Full Screen

index.spec.js

Source:index.spec.js Github

copy

Full Screen

...51 afterEach(() => {52 jest.resetAllMocks();53 });54 it('method getApplicants returns right data', async () => {55 const mockFindAndCountAll = jest.spyOn(Applicant, 'findAndCountAll').mockReturnValue(applicantsData);56 const query = {57 countPerPage: 25,58 page: 0,59 };60 const applicants = await new ApplicantService({ ...req, query }).getApplicants();61 const { options } = getExecOptions(query);62 expect(mockFindAndCountAll).toBeCalledWith(options);63 expect(applicants).toMatchObject(applicantsData);64 });65 it('method getApplicant returns right data', async () => {66 const mockFindByPk = jest.spyOn(Applicant, 'findByPk').mockReturnValue(applicantsData.rows[0]);67 const id = 1;68 const params = { id };69 const applicants = await new ApplicantService({ ...req, params }).getApplicant();70 expect(mockFindByPk).toBeCalledWith(id, { include: includeModelsFull, attributes: attributesFull });71 expect(applicants).toMatchObject(applicantsData.rows[0]);72 });73 it('method update throw error if applicant not found', async () => {74 const id = 1;75 const params = { id };76 const body = {};77 try {78 const mockFindByPk = jest.spyOn(Applicant, 'findByPk').mockReturnValue(null);79 await new ApplicantService({ ...req, body, params }).update();80 expect(mockFindByPk).toBeCalledWith(id, { include: includeModelsFull });81 } catch (err) {82 expect(err.statusCode).toBe(StatusCodes.BAD_REQUEST);83 expect(err.message).toBe(`Applicant with id: ${id} not found in database`);84 }85 });86 it('method create create applicant', async () => {87 const id = 1;88 const body = { ...applicantsData.rows[0] };89 const mockFindByPk = jest.spyOn(Applicant, 'findByPk').mockReturnValue({ ...applicantsData.rows[0] });90 const mockCreate = jest.spyOn(Applicant, 'create').mockReturnValue({ ...applicantsData.rows[0] });91 const mockSalary = jest.spyOn(Salary.prototype, 'set').mockImplementation(() => {});92 const mockEduction = jest.spyOn(Education.prototype, 'set').mockImplementation(() => {});93 const mockPositions = jest.spyOn(Positions.prototype, 'add').mockImplementation(() => {});94 const mockSkills = jest.spyOn(Skills.prototype, 'add').mockImplementation(() => {});95 const mockWorkPlaces = jest.spyOn(WorkPlaces.prototype, 'add').mockImplementation(() => {});96 const mockRegions = jest.spyOn(Regions.prototype, 'add').mockImplementation(() => {});97 const mockLanguageSkills = jest.spyOn(LanguageSkills.prototype, 'add').mockImplementation(() => {});98 const mockPhotos = jest.spyOn(Photos.prototype, 'create').mockImplementation(() => {});99 const mockSex = jest.spyOn(Sex.prototype, 'set').mockImplementation(() => {});100 const mockPhones = jest.spyOn(Phones.prototype, 'create').mockImplementation(() => {});101 const mockEmails = jest.spyOn(Emails.prototype, 'create').mockImplementation(() => {});102 const mockMessengers = jest.spyOn(Messengers.prototype, 'create').mockImplementation(() => {});103 const mockLinks = jest.spyOn(Links.prototype, 'create').mockImplementation(() => {});104 const mockFiles = jest.spyOn(Files.prototype, 'create').mockImplementation(() => {});105 const mockExperiences = jest.spyOn(Experiences.prototype, 'create').mockImplementation(() => {});106 const mockExperienceYear = jest.spyOn(ExperienceYear.prototype, 'set').mockImplementation(() => {});107 const applicant = await new ApplicantService({ ...req, body }).create();108 expect(mockCreate).toBeCalledTimes(1);109 expect(mockFindByPk).toBeCalledWith(id, { include: includeModelsLight, attributes: attributesLight });110 expect(applicant).toMatchObject(body);111 expect(mockSalary).toBeCalled();112 expect(mockEduction).toBeCalled();113 expect(mockPositions).toBeCalled();114 expect(mockSkills).toBeCalled();115 expect(mockWorkPlaces).toBeCalled();116 expect(mockRegions).toBeCalled();117 expect(mockLanguageSkills).toBeCalled();118 expect(mockPhotos).toBeCalled();119 expect(mockSex).toBeCalled();120 expect(mockPhones).toBeCalled();121 expect(mockEmails).toBeCalled();122 expect(mockMessengers).toBeCalled();123 expect(mockLinks).toBeCalled();124 expect(mockFiles).toBeCalled();125 expect(mockExperiences).toBeCalled();126 expect(mockExperienceYear).toBeCalled();127 });128 it('method create throws an error', async () => {129 try {130 const body = { ...applicantsData.rows[0] };131 jest.spyOn(Applicant, 'create').mockImplementation(() => {132 throw new UnexpectedError('Something went wrong');133 });134 await new ApplicantService({ ...req, body }).create();135 } catch (err) {136 expect(err.statusCode).toBe(StatusCodes.INTERNAL_SERVER_ERROR);137 expect(err.message).toBe('Something went wrong');138 }139 });140 it('method update works right', async () => {141 const id = 1;142 const params = { id };143 const body = {144 ...applicantsData.rows[0],145 name: 'Updated Name',146 };147 const mockSave = jest.fn();148 let callCount = 1;149 const mockFindByPk = jest.spyOn(Applicant, 'findByPk').mockImplementation(() => {150 if (callCount === 1) {151 callCount++;152 return { save: mockSave.mockReturnValue(body) };153 }154 if (callCount === 2) {155 callCount++;156 return { ...body };157 }158 });159 const mockSalary = jest.spyOn(Salary.prototype, 'update').mockImplementation(() => {});160 const mockEduction = jest.spyOn(Education.prototype, 'update').mockImplementation(() => {});161 const mockPositions = jest.spyOn(Positions.prototype, 'update').mockImplementation(() => {});162 const mockSkills = jest.spyOn(Skills.prototype, 'update').mockImplementation(() => {});163 const mockWorkPlaces = jest.spyOn(WorkPlaces.prototype, 'update').mockImplementation(() => {});164 const mockRegions = jest.spyOn(Regions.prototype, 'update').mockImplementation(() => {});165 const mockLanguageSkills = jest.spyOn(LanguageSkills.prototype, 'update').mockImplementation(() => {});166 const mockPhotos = jest.spyOn(Photos.prototype, 'update').mockImplementation(() => {});167 const mockSex = jest.spyOn(Sex.prototype, 'update').mockImplementation(() => {});168 const mockPhones = jest.spyOn(Phones.prototype, 'update').mockImplementation(() => {});169 const mockEmails = jest.spyOn(Emails.prototype, 'update').mockImplementation(() => {});170 const mockMessengers = jest.spyOn(Messengers.prototype, 'update').mockImplementation(() => {});171 const mockLinks = jest.spyOn(Links.prototype, 'update').mockImplementation(() => {});172 const mockFiles = jest.spyOn(Files.prototype, 'update').mockImplementation(() => {});173 const mockExperiences = jest.spyOn(Experiences.prototype, 'update').mockImplementation(() => {});174 const mockExperienceYear = jest.spyOn(ExperienceYear.prototype, 'update').mockImplementation(() => {});175 const applicant = await new ApplicantService({ ...req, body, params }).update();176 expect(mockFindByPk).toBeCalledWith(id, { include: includeModelsFull });177 expect(mockFindByPk).toBeCalledTimes(2);178 expect(applicant).toMatchObject(body);179 expect(mockSalary).toBeCalled();180 expect(mockEduction).toBeCalled();181 expect(mockPositions).toBeCalled();182 expect(mockSkills).toBeCalled();183 expect(mockWorkPlaces).toBeCalled();184 expect(mockRegions).toBeCalled();185 expect(mockLanguageSkills).toBeCalled();186 expect(mockPhotos).toBeCalled();187 expect(mockSex).toBeCalled();188 expect(mockPhones).toBeCalled();189 expect(mockEmails).toBeCalled();190 expect(mockMessengers).toBeCalled();191 expect(mockLinks).toBeCalled();192 expect(mockFiles).toBeCalled();193 expect(mockExperiences).toBeCalled();194 expect(mockExperienceYear).toBeCalled();195 });196 it('method update throws an error', async () => {197 try {198 const id = 1;199 const body = { ...applicantsData.rows[0] };200 const params = { id };201 jest.spyOn(Applicant, 'findByPk').mockImplementation(() => {202 throw new UnexpectedError('Something went wrong');203 });204 await new ApplicantService({ ...req, body, params }).update();205 } catch (err) {206 expect(err.statusCode).toBe(StatusCodes.INTERNAL_SERVER_ERROR);207 expect(err.message).toBe('Something went wrong');208 }209 });210 it('method delete calls destroy', async () => {211 const id = 1;212 const mockSalary = jest.spyOn(Salary.prototype, 'delete').mockImplementation(() => {});213 const mockPositions = jest.spyOn(Positions.prototype, 'delete').mockImplementation(() => {});214 const mockSkills = jest.spyOn(Skills.prototype, 'delete').mockImplementation(() => {});215 const mockWorkPlaces = jest.spyOn(WorkPlaces.prototype, 'delete').mockImplementation(() => {});216 const mockRegions = jest.spyOn(Regions.prototype, 'delete').mockImplementation(() => {});217 const mockLanguageSkills = jest.spyOn(LanguageSkills.prototype, 'delete').mockImplementation(() => {});218 const mockPhotos = jest.spyOn(Photos.prototype, 'delete').mockImplementation(() => {});219 const mockPhones = jest.spyOn(Phones.prototype, 'delete').mockImplementation(() => {});220 const mockEmails = jest.spyOn(Emails.prototype, 'delete').mockImplementation(() => {});221 const mockMessengers = jest.spyOn(Messengers.prototype, 'delete').mockImplementation(() => {});222 const mockLinks = jest.spyOn(Links.prototype, 'delete').mockImplementation(() => {});223 const mockFiles = jest.spyOn(Files.prototype, 'delete').mockImplementation(() => {});224 const mockExperiences = jest.spyOn(Experiences.prototype, 'delete').mockImplementation(() => {});225 const mockExperienceYear = jest.spyOn(ExperienceYear.prototype, 'delete').mockImplementation(() => {});226 const mockDestroy = jest.spyOn(Applicant, 'destroy').mockImplementation(() => {});227 await new ApplicantService({ ...req, params: { id } }).delete();228 expect(mockDestroy).toBeCalledWith({ where: { id } });229 expect(mockSalary).toBeCalledWith(id);230 expect(mockPositions).toBeCalledWith(id);231 expect(mockSkills).toBeCalledWith(id);232 expect(mockWorkPlaces).toBeCalledWith(id);233 expect(mockRegions).toBeCalledWith(id);234 expect(mockLanguageSkills).toBeCalledWith(id);235 expect(mockPhotos).toBeCalledWith(id);236 expect(mockPhones).toBeCalledWith(id);237 expect(mockEmails).toBeCalledWith(id);238 expect(mockMessengers).toBeCalledWith(id);239 expect(mockLinks).toBeCalledWith(id);240 expect(mockFiles).toBeCalledWith(id);...

Full Screen

Full Screen

mockedComplexOperations.test.js

Source:mockedComplexOperations.test.js Github

copy

Full Screen

...6 jest.restoreAllMocks();7});8 describe('checkEmail', () => {9 it('First test for checkEmail', () => {10 jest.spyOn(basicOperations, 'isString').mockReturnValue(false);11 expect(complexOperations.checkEmail(10)).toBe('The email should be an string');12 });13 it('Second test for checkEmail', () => {14 jest.spyOn(basicOperations, 'validateEmail').mockReturnValue(false);15 expect(complexOperations.checkEmail('Narella')).toBe('The email is invalid');16 });17 it('Third test for checkEmail', () => {18 jest.spyOn(basicOperations, 'validateEmail').mockReturnValue(true);19 expect(complexOperations.checkEmail('narellacalvente@gmail.com')).toBe('The email is valid');20 });21 });22 describe('calculateArea', () => {23 it('First test for calculateArea', () => {24 jest.spyOn(basicOperations, 'isSupportedFigure').mockReturnValue(false);25 expect(complexOperations.calculateArea('hexagon')).toBe(`${'hexagon'} is not supported`);26 });27 it('Second test for calculateArea', () => {28 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(false);29 expect(complexOperations.calculateArea('square', 'five', 'ten')).toBe('number1 and number2 should be numbers');30 });31 it('Third test for calculateArea', () => {32 jest.spyOn(basicOperations, 'isSupportedFigure').mockReturnValue(true);33 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(true);34 jest.spyOn(basicOperations, 'multip').mockReturnValue(25);35 expect(complexOperations.calculateArea('square', 5, 5)).toBe(25);36 });37 it('Four test for calculateArea', () => {38 jest.spyOn(basicOperations, 'isSupportedFigure').mockReturnValue(true);39 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(true);40 jest.spyOn(basicOperations, 'multip').mockReturnValue(50);41 expect(complexOperations.calculateArea('rectangle', 5, 10)).toBe(50);42 });43 it('Five test for calculateArea', () => {44 jest.spyOn(basicOperations, 'isSupportedFigure').mockReturnValue(true);45 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(true);46 jest.spyOn(basicOperations, 'division').mockReturnValue(16);47 expect(complexOperations.calculateArea('triangle', 4, 8)).toBe(16);48 });49 it('Six test for calculateArea', () => {50 jest.spyOn(basicOperations, 'isSupportedFigure').mockReturnValue(true);51 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(true);52 jest.spyOn(basicOperations, 'exponent').mockReturnValue(100);53 expect(complexOperations.calculateArea('circle', 10)).toBe(Math.PI * 100);54 });55 });56 describe('sumGratherThan', () => {57 it('First test for sumGratherThan', () => {58 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(false);59 expect(complexOperations.sumGratherThan('five', 'six', 'seven')).toBe('The params should be numbers');60 });61 it('Second test for sumGratherThan', () => {62 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(true);63 jest.spyOn(basicOperations, 'sum').mockReturnValue(9);64 expect(complexOperations.sumGratherThan(4, 5, 6)).toBe(`${9} is grather than ${6}`);65 });66 it('Third test for sumGratherThan', () => {67 jest.spyOn(basicOperations, 'isNumber').mockReturnValue(true);68 jest.spyOn(basicOperations, 'sum').mockReturnValue(4);69 expect(complexOperations.sumGratherThan(2, 2, 6)).toBe(`${4} is less than ${6}`);70 });71 });72 describe('intersectionBetweenArrays', () => {73 it('First test for intersectionBetweenArrays', () => {74 jest.spyOn(basicOperations, 'isArray').mockReturnValue(false);75 expect(complexOperations.intersectionBetweenArrays('hello', 5)).toBe('The params should be arrays');76 });77 it('Second test for intersectionBetweenArrays', () => {78 jest.spyOn(basicOperations, 'isArray').mockReturnValue(true);79 expect(complexOperations.intersectionBetweenArrays(['apple', 'banana', 'orange'], ['one', 'two', 'three'])).toBe('There are not matching elements');80 });81 it('Third test for intersectionBetweenArrays', () => {82 jest.spyOn(basicOperations, 'isArray').mockReturnValue(true);83 jest.spyOn(basicOperations, 'arrayIntersection').mockReturnValue('apple');84 expect(complexOperations.intersectionBetweenArrays(['apple', 'banana', 'orange'], ['one', 'apple', 'three'])).toEqual('apple');85 });86 });87 describe('sortArrayOfObjectsByKey', () => {88 it('First test for sortArrayOfObjectsByKey', () => {89 jest.spyOn(basicOperations, 'isArray').mockReturnValue(false);90 expect(complexOperations.sortArrayOfObjectsByKey('hello')).toBe('The first param should be an array');91 });92 it('Second test for sortArrayOfObjectsByKey', () => {93 jest.spyOn(basicOperations, 'isArray').mockReturnValue(true);94 jest.spyOn(basicOperations, 'isString').mockReturnValue(false);95 expect(complexOperations.sortArrayOfObjectsByKey([5, 6])).toBe('The second param should be an string');96 });97 it('Third test for sortArrayOfObjectsByKey', () => {98 jest.spyOn(basicOperations, 'isArray').mockReturnValue(true);99 jest.spyOn(basicOperations, 'isString').mockReturnValue(true);100 jest.spyOn(basicOperations, 'arrayElementsAreObjectWithKey').mockReturnValue(false)101 expect(complexOperations.sortArrayOfObjectsByKey([{position: 'One'}, {position:'Two'}, {place: 'Three'}], 'position')).toEqual('Some elements in the array does not have the position property');102 });103 it('Four test for sortArrayOfObjectsByKey', () => {104 const expectedArray = [{"position": "One"}, {"position": "Three"}, {"position": "Two"}];105 jest.spyOn(basicOperations, 'isArray').mockReturnValue(true);106 jest.spyOn(basicOperations, 'isString').mockReturnValue(true);107 jest.spyOn(basicOperations, 'arrayElementsAreObjectWithKey').mockReturnValue(true);108 jest.spyOn(basicOperations, 'sortArrayByKey').mockReturnValue(expectedArray);109 expect(complexOperations.sortArrayOfObjectsByKey([], 'position')).toStrictEqual(expectedArray);110 });111 });112 describe('numberOfOddAndEvenNumbers', () => {113 it('First test for numberOfOddAndEvenNumbers', () => {114 jest.spyOn(basicOperations, 'isArray').mockReturnValue(false);115 expect(complexOperations.numberOfOddAndEvenNumbers('hello')).toBe('The param should be an array');116 });117 it('Second test for numberOfOddAndEvenNumbers', () => {118 expect(complexOperations.numberOfOddAndEvenNumbers(['hello', 'world'])).toBe(`The array should have only numbers`);119 });120 it('Third test for numberOfOddAndEvenNumbers', () => {121 jest.spyOn(basicOperations, 'isArray').mockReturnValue(true);122 jest.spyOn(basicOperations, 'getOddNumbersFromArray').mockReturnValue([5, 7]);123 jest.spyOn(basicOperations, 'getEvenNumbersFromArray').mockReturnValue([2, 4, 6, 8]);124 expect(complexOperations.numberOfOddAndEvenNumbers([])).toEqual({"even": 4, "odd": 2});125 });126 });...

Full Screen

Full Screen

auth.spec.ts

Source:auth.spec.ts Github

copy

Full Screen

...20 passwordService = new PasswordService();21 service = new AuthService(tokenService, mailService, urlService, userRepository, passwordService);22 });23 it('should return token for a valid user when try to login', async () => {24 jest.spyOn(userRepository, 'findByEmail').mockResolvedValueOnce({ password: 'senha' } as any);25 jest.spyOn(passwordService, 'compare').mockResolvedValueOnce(true);26 jest.spyOn(tokenService, 'generateAccessToken').mockResolvedValueOnce('app_access_token');27 const result = await service.login('email', 'senha');28 expect(result).not.toBeFalsy();29 expect(result).toEqual('app_access_token');30 });31 it('should throw NotFoundException when user was not found', async () => {32 jest.spyOn(userRepository, 'findByEmail').mockResolvedValueOnce(null);33 try {34 await service.login('email', 'senha');35 fail();36 } catch (err) {37 expect(err).toBeInstanceOf(NotFoundException);38 }39 });40 it('should throw BadRequestException when password doesn`t match', async () => {41 jest.spyOn(userRepository, 'findByEmail').mockResolvedValueOnce({ password: 'senha' } as any);42 jest.spyOn(passwordService, 'compare').mockResolvedValueOnce(false);43 try {44 await service.login('email', 'senha');45 fail();46 } catch (err) {47 expect(err).toBeInstanceOf(BadRequestException);48 }49 });50 it('should return user when try to change password', async () => {51 jest.spyOn(userRepository, 'findById').mockResolvedValueOnce({ id: 1, password: '123@senha' } as any);52 jest.spyOn(userRepository, 'update').mockImplementationOnce(model => Promise.resolve(model as any));53 jest.spyOn(passwordService, 'compare').mockResolvedValueOnce(true);54 jest.spyOn(passwordService, 'hash').mockResolvedValueOnce('hashpassword');55 const user = await service.changePassword({ id: 1 } as any, '123@senha', '1234@senha');56 expect(user.password).toBe('hashpassword');57 });58 it('should throw BadRequestException when try to change password and the password doesn`t match', async () => {59 jest.spyOn(userRepository, 'findById').mockResolvedValueOnce({ id: 1, password: '123@senha' } as any);60 jest.spyOn(passwordService, 'compare').mockResolvedValueOnce(false);61 try {62 await service.changePassword({ id: 1 } as any, '123@senha', '1234@senha');63 fail();64 } catch (err) {65 expect(err).toBeInstanceOf(BadRequestException);66 }67 });68 it('should sendResetPassword', async () => {69 jest70 .spyOn(userRepository, 'findByEmail')71 .mockResolvedValueOnce({ id: 1, password: '123@senha', email: 'teste@email.com' } as any);72 jest.spyOn(tokenService, 'resetPassword').mockResolvedValueOnce('resetPassword');73 jest.spyOn(urlService, 'resetPassword').mockReturnValueOnce('urlResetPassword');74 jest75 .spyOn(mailService, 'send')76 .mockImplementationOnce((to, subject, template, data) =>77 Promise.resolve({ to, subject, template, data, html: '', from: '' })78 );79 const mail = await service.sendResetPassword('teste@email.com');80 expect(mail.to).toBe('teste@email.com');81 expect(mail.subject).toBe('Recuperar Acesso');82 expect(mail.template).toBe('user-reset-password');83 expect((mail as any).data.url).toBe('urlResetPassword');84 });85 it('should throw NotFoundException when try to sendPassword and user was not found', async () => {86 jest.spyOn(userRepository, 'findByEmail').mockResolvedValueOnce(null);87 try {88 await service.sendResetPassword('teste@email.com');89 fail();90 } catch (err) {91 expect(err).toBeInstanceOf(NotFoundException);92 }93 });94 it('should changePassword', async () => {95 jest.spyOn(tokenService, 'verify').mockResolvedValueOnce({ id: 1 } as any);96 jest.spyOn(userRepository, 'findById').mockResolvedValueOnce({ id: 1 } as any);97 jest.spyOn(passwordService, 'hash').mockResolvedValueOnce('hashPassword');98 jest.spyOn(userRepository, 'update').mockImplementationOnce(model => Promise.resolve(model as any));99 const user = await service.resetPassword('token', 'newPassowrd');100 expect(user.password).toBe('hashPassword');101 });102 it('should throw NotFoundException when try to changePassword and user was not found', async () => {103 jest.spyOn(tokenService, 'verify').mockResolvedValueOnce({ id: 1 } as any);104 jest.spyOn(userRepository, 'findById').mockResolvedValueOnce(null);105 try {106 await service.resetPassword('token', 'newPassowrd');107 fail();108 } catch (err) {109 expect(err).toBeInstanceOf(NotFoundException);110 }111 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require('qawolf');2const selectors = require('./selectors/test.json');3describe('test', () => {4 let browser;5 beforeAll(async () => {6 browser = await launch();7 });8 afterAll(async () => {9 await browser.close();10 });11 it('test', async () => {12 const page = await browser.newPage();13 await page.click(selectors['#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type="submit"]:nth-child(1)']);14 });15});16{17 "#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type=\"submit\"]:nth-child(1)": {18 "id": "tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type=\"submit\"]:nth-child(1)",19 "selector": "#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type=\"submit\"]:nth-child(1)",20 "#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type=\"submit\"]:nth-child(1)"21 }22}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require("@playwright/test");2const { launch } = require("qawolf");3const { createBrowser } = require("qawolf");4const { createPage } = require("qawolf");5const { createPage } = require("qawolf");6const { createBrowser } = require("qawolf");7const { launch } = require("qawolf");8const { test, expect } = require("@playwright/test");9const { launch } = require("qawolf");10const { createBrowser } = require("qawolf");11const { createPage } = require("qawolf");12const { createPage } = require("qawolf");13const { createBrowser } = require("qawolf");14const { launch } = require("qawolf");15const { test, expect } = require("@playwright/test");16const { launch } = require("qawolf");17const { createBrowser } = require("qawolf");18const { createPage } = require("qawolf");19const { createPage } = require("qawolf");20const { createBrowser } = require("qawolf");21const { launch } = require("qawolf");22const { test, expect } = require("@playwright/test");23const { launch } = require("qawolf");24const { createBrowser } = require("qawolf");25const { createPage } = require("qawolf");26const { createPage } = require("qawolf");27const { createBrowser } = require("qawolf");28const { launch } = require("qawolf");29const { test, expect } = require("@playwright/test");30const { launch } = require("qawolf");31const { createBrowser } = require("qawolf");32const { createPage } = require("qawolf");33const { createPage } = require("qawolf");34const { createBrowser } = require("qawolf");35const { launch } = require("qawolf");36const { test, expect } = require("@playwright/test");37const { launch } = require("qawolf");38const { createBrowser } = require("qawolf");39const { createPage } = require("qawolf");40const { createPage } = require("qawolf");41const { createBrowser } = require("qawolf");42const { launch } = require("qawolf");

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const { mockRequest } = require("qawolf");3jest.spyOn(qawolf, "mockRequest");4describe("test", () => {5 it("test", async () => {6 mockRequest.mockImplementation((...args) => {7 console.log("mockRequest", ...args);8 return { status: 200 };9 });10 const { browser, context, page } = await qawolf.createBrowser();11 await qawolf.create();12 });13});14const qawolf = require("qawolf");15const { mockRequest } = require("qawolf");16jest.spyOn(qawolf, "mockRequest");17describe("test", () => {18 it("test", async () => {19 mockRequest.mockImplementation((...args) => {20 console.log("mockRequest", ...args);21 return { status: 200 };22 });23 const { browser, context, page } = await qawolf.createBrowser();24 await qawolf.create();25 });26});27const qawolf = require("qawolf");28const { mockRequest } = require("qawolf");29jest.spyOn(qawolf, "mockRequest");

Full Screen

Using AI Code Generation

copy

Full Screen

1import { run } from 'qawolf';2import { test } from './test';3describe('test', () => {4 it('test', async () => {5 const page = await browser.page();6 const spy = jest.spyOn(page, 'waitForSelector');7 await test(page);8 expect(spy).toHaveBeenCalledWith('input[name="q"]');9 await browser.close();10 });11});12import { create } from 'qawolf';13import { test } from './test';14describe('test', () => {15 it('test', async () => {16 const page = await browser.page();17 await test(page);18 await browser.close();19 });20});21import { create } from 'qawolf';22import { test } from './test';23describe('test', () => {24 it('test', async () => {25 const page = await browser.page();26 await test(page);27 await browser.close();28 });29});30import { run, create, test } from 'qawolf';31const testFn = process.env.QAW_CREATE ? create : run;32describe('test', () => {33 it('test', async () => {34 const page = await browser.page();35 await test(page);36 await browser.close();37 });38});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { launch } from "qawolf";2import { Browser } from "puppeteer";3import { spy } from "sinon";4describe("test", () => {5 let browser: Browser;6 let page: any;7 beforeAll(async () => {8 browser = await launch();9 page = await browser.newPage();10 });11 afterAll(async () => {12 await browser.close();13 });14 it("test", async () => {15 const spyOn = spy(page, "waitForSelector");16 const spyOn = spy(page, "waitForSelector");17 await page.click('[data-testid="search-input"]');18 await page.type('[data-testid="search-input"]', "test");19 await page.click('[data-testid="search-button"]');20 await page.waitForSelector('[data-testid="search-results"]');21 await page.click('[data-testid="search-results"]');22 expect(spyOn.calledOnce).toBe(true);23 });24});25import { launch } from "qawolf";26import { Browser } from "puppeteer";27import { spy } from "sinon";28describe("test", () => {29 let browser: Browser;30 let page: any;31 beforeAll(async () => {32 browser = await launch();33 page = await browser.newPage();34 });35 afterAll(async () => {36 await browser.close();37 });38 it("test", async () => {39 const spyOn = spy(page,

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful