From 014b07776a69f568e7b668db3fd5205e14fcfdd6 Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Mon, 30 Oct 2023 23:23:31 +0000 Subject: [PATCH 1/7] initialized escape game model/controller/service/route and get available theaters name --- src/app.ts | 1 + .../theaters/theaters.controller.ts | 18 +++ src/docs/swagger-output.json | 106 ++++++++++++++++-- src/models/theater-escape-game.model.ts | 10 ++ src/routes/theaters.ts | 12 ++ src/services/scapping/scrapping.servive.ts | 69 ++++++++++++ 6 files changed, 209 insertions(+), 7 deletions(-) create mode 100644 src/models/theater-escape-game.model.ts diff --git a/src/app.ts b/src/app.ts index 6db82dc..f23f3de 100644 --- a/src/app.ts +++ b/src/app.ts @@ -84,6 +84,7 @@ class App { this.app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)) this.app.use('/movies', moviesRouter); this.app.use('/theaters', theatersRouter); + this.app.use('/escape', theatersRouter); } diff --git a/src/controllers/theaters/theaters.controller.ts b/src/controllers/theaters/theaters.controller.ts index 838f088..ae86fae 100644 --- a/src/controllers/theaters/theaters.controller.ts +++ b/src/controllers/theaters/theaters.controller.ts @@ -65,5 +65,23 @@ export default class TheatersController implements BaseController { }) } } + + public async getAllEscapeGame(res: Response): Promise { + try { + const data = await this.scrappingService.AllEscapeGame(); + return res.status(StatusCodes.OK).json(data); + + }catch(error) { + const e = error as Error; + + this.logger.warn('getTheatersNames'); + this.logger.warn(e.message); + + return res.status(StatusCodes.BAD_REQUEST).json({ + message: ReasonPhrases.BAD_REQUEST, + errors: e.message, + }) + } + } } \ No newline at end of file diff --git a/src/docs/swagger-output.json b/src/docs/swagger-output.json index 3e59eca..e519b9b 100644 --- a/src/docs/swagger-output.json +++ b/src/docs/swagger-output.json @@ -39,6 +39,20 @@ } } }, + "/status": { + "get": { + "tags": [ + "/" + ], + "summary": "Redirect to the health status page", + "description": "", + "responses": { + "default": { + "description": "" + } + } + } + }, "/movies": { "get": { "tags": [ @@ -251,7 +265,7 @@ } } }, - "/movies/{theater}": { + "/movies/{theaterSlug}": { "get": { "tags": [ "Movies" @@ -260,7 +274,7 @@ "description": "Fetch all the available movies at a given theater", "parameters": [ { - "name": "theater", + "name": "theaterSlug", "in": "path", "required": true, "schema": { @@ -710,7 +724,7 @@ } }, { - "name": "theater", + "name": "theaterSlug", "in": "query", "schema": { "type": "string" @@ -1000,7 +1014,86 @@ } } }, - "/theaters/infos/{theater}": { + "/theaters/escape-game": { + "get": { + "tags": [ + "Theaters" + ], + "summary": "Fetch all the available theaters name", + "description": "Return an array of strings with the theaters name", + "responses": { + "200": { + "description": "Ok", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TheaterName" + }, + "xml": { + "name": "main" + } + } + }, + "application/xml": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TheaterName" + }, + "xml": { + "name": "main" + } + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Bad Request" + }, + "errors": { + "type": "string", + "example": "any" + } + }, + "xml": { + "name": "main" + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Bad Request" + }, + "errors": { + "type": "string", + "example": "any" + } + }, + "xml": { + "name": "main" + } + } + } + } + } + } + } + }, + "/theaters/infos/{theaterSlug}": { "get": { "tags": [ "Theaters" @@ -1009,7 +1102,7 @@ "description": "Fetch informations about a specified theater giving his name", "parameters": [ { - "name": "theater", + "name": "theaterSlug", "in": "path", "required": true, "schema": { @@ -1431,6 +1524,5 @@ } } } - }, - "url": "http://51.91.76.77:3123" + } } \ No newline at end of file diff --git a/src/models/theater-escape-game.model.ts b/src/models/theater-escape-game.model.ts new file mode 100644 index 0000000..eaf5f35 --- /dev/null +++ b/src/models/theater-escape-game.model.ts @@ -0,0 +1,10 @@ +export default interface TheaterEscapeGameModel { + name: string, + img: string, + price: number, + groupSizeMin: number, + groupSizeMax: number, + difficulty: number, + description: string, + minAge: number, +} \ No newline at end of file diff --git a/src/routes/theaters.ts b/src/routes/theaters.ts index 2c66cd2..4d4e7c6 100644 --- a/src/routes/theaters.ts +++ b/src/routes/theaters.ts @@ -47,6 +47,18 @@ router.get( } ); +router.get('/escape-game', + + ExpressValidatorMiddleware, + + async function (req, res, _next) { + const response = theatersController.getAllEscapeGame(res); + return response; + } + +); + + router.get( '/infos/:theaterSlug', diff --git a/src/services/scapping/scrapping.servive.ts b/src/services/scapping/scrapping.servive.ts index 4130b9d..faf4f35 100644 --- a/src/services/scapping/scrapping.servive.ts +++ b/src/services/scapping/scrapping.servive.ts @@ -9,6 +9,7 @@ import TheaterInfosModel from "../../models/theater-info.model"; import TheaterNameModel from "@/models/theater-name.model"; import axios, { AxiosError, AxiosResponse } from "axios"; import * as cheerio from 'cheerio'; +import TheaterEscapeGameModel from "@/models/theater-escape-game.model"; export default class ScrappingService implements BaseService { @@ -431,6 +432,74 @@ export default class ScrappingService implements BaseService { return theaterInfos; } + public async escapeGameByTheaters() { + let response: AxiosResponse; + try { + response = await axios.get(infos.baseUrl); + } catch (error) { + + const e = error as AxiosError; + + this.logger.fatal('theatersNames'); + this.logger.fatal(e); + + throw Error(e.message); + } + + try { + + // my logic + + } catch (error) { + + this.logger.fatal('theater slugs'); + this.logger.fatal((error as Error).message); + + throw Error((error as Error).message); + } + } + + public async AllEscapeGame(): Promise { + let response: AxiosResponse; + try { + response = await axios.get(`${infos.baseUrl}/escape-game/`); + } catch (error) { + + const e = error as AxiosError; + + this.logger.fatal('theatersNames'); + this.logger.fatal(e); + + throw Error(e.message); + } + + const htmlRoot = cheerio.load(response.data); + const elements = htmlRoot("article"); + let avalaibleTheatherName: String[] = [] ; + htmlRoot("ul.theaters li").each((index ,element) => { + avalaibleTheatherName.push( htmlRoot(element).data("set") as String ); + }); + + avalaibleTheatherName.forEach((name) => { + const escapeElement = htmlRoot(`article[data-${name}]`) ; + console.log(escapeElement?.length); + }) + const theaterEscapeGame: TheaterEscapeGameModel = { + name: "", + img: "", + price: 0, + groupSizeMin: 0, + groupSizeMax: 0, + difficulty: 0, + description: "", + minAge: 0, + } + + + return theaterEscapeGame; + + } + } From 31683c883e224b080526d14e1e5ab18cec4acee4 Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Wed, 1 Nov 2023 10:00:07 +0000 Subject: [PATCH 2/7] fetching all escape games from available theaters --- .../theaters/theaters.controller.ts | 6 +- src/docs/swagger-output.json | 243 +++++++++++++++++- src/models/theater-escape-game.model.ts | 1 + src/routes/theaters.ts | 2 +- src/services/scapping/scrapping.servive.ts | 69 ++--- 5 files changed, 285 insertions(+), 36 deletions(-) diff --git a/src/controllers/theaters/theaters.controller.ts b/src/controllers/theaters/theaters.controller.ts index ae86fae..c903330 100644 --- a/src/controllers/theaters/theaters.controller.ts +++ b/src/controllers/theaters/theaters.controller.ts @@ -65,10 +65,10 @@ export default class TheatersController implements BaseController { }) } } - - public async getAllEscapeGame(res: Response): Promise { + + public async getAllEscapeGames(res: Response): Promise { try { - const data = await this.scrappingService.AllEscapeGame(); + const data = await this.scrappingService.AllEscapeGames(); return res.status(StatusCodes.OK).json(data); }catch(error) { diff --git a/src/docs/swagger-output.json b/src/docs/swagger-output.json index e519b9b..5da7e6f 100644 --- a/src/docs/swagger-output.json +++ b/src/docs/swagger-output.json @@ -1015,6 +1015,237 @@ } }, "/theaters/escape-game": { + "get": { + "description": "", + "responses": { + "default": { + "description": "" + } + } + } + }, + "/theaters/infos/{theaterSlug}": { + "get": { + "tags": [ + "Theaters" + ], + "summary": "Fetch informations about a specified theater giving his name", + "description": "Fetch informations about a specified theater giving his name", + "parameters": [ + { + "name": "theaterSlug", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "lang", + "in": "query", + "description": "The response language", + "schema": { + "type": "string", + "enum": [ + "fr", + "en" + ] + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TheaterInfos" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/TheaterInfos" + } + } + } + }, + "400": { + "description": "Bad request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Bad request" + }, + "errors": { + "type": "string", + "example": "any" + } + }, + "xml": { + "name": "main" + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Bad request" + }, + "errors": { + "type": "string", + "example": "any" + } + }, + "xml": { + "name": "main" + } + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Theater not found" + }, + "errors": { + "type": "array", + "example": [], + "items": {} + } + }, + "xml": { + "name": "main" + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Theater not found" + }, + "errors": { + "type": "array", + "example": [], + "items": {} + } + }, + "xml": { + "name": "main" + } + } + } + } + }, + "422": { + "description": "Your body was bad formatted", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Your body was bad formatted" + }, + "errors": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string", + "example": "field" + }, + "value": { + "type": "string", + "example": "zk" + }, + "msg": { + "type": "string", + "example": "Invalid value" + }, + "path": { + "type": "string", + "example": "lang" + }, + "location": { + "type": "string", + "example": "query" + } + } + } + } + }, + "xml": { + "name": "main" + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "example": "Your body was bad formatted" + }, + "errors": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string", + "example": "field" + }, + "value": { + "type": "string", + "example": "zk" + }, + "msg": { + "type": "string", + "example": "Invalid value" + }, + "path": { + "type": "string", + "example": "lang" + }, + "location": { + "type": "string", + "example": "query" + } + } + } + } + }, + "xml": { + "name": "main" + } + } + } + } + } + } + } + }, + "/escape/names": { "get": { "tags": [ "Theaters" @@ -1093,7 +1324,17 @@ } } }, - "/theaters/infos/{theaterSlug}": { + "/escape/escape-game": { + "get": { + "description": "", + "responses": { + "default": { + "description": "" + } + } + } + }, + "/escape/infos/{theaterSlug}": { "get": { "tags": [ "Theaters" diff --git a/src/models/theater-escape-game.model.ts b/src/models/theater-escape-game.model.ts index eaf5f35..91968f3 100644 --- a/src/models/theater-escape-game.model.ts +++ b/src/models/theater-escape-game.model.ts @@ -1,4 +1,5 @@ export default interface TheaterEscapeGameModel { + theaterName : string , name: string, img: string, price: number, diff --git a/src/routes/theaters.ts b/src/routes/theaters.ts index 4d4e7c6..780e771 100644 --- a/src/routes/theaters.ts +++ b/src/routes/theaters.ts @@ -52,7 +52,7 @@ router.get('/escape-game', ExpressValidatorMiddleware, async function (req, res, _next) { - const response = theatersController.getAllEscapeGame(res); + const response = theatersController.getAllEscapeGames(res); return response; } diff --git a/src/services/scapping/scrapping.servive.ts b/src/services/scapping/scrapping.servive.ts index faf4f35..913c728 100644 --- a/src/services/scapping/scrapping.servive.ts +++ b/src/services/scapping/scrapping.servive.ts @@ -446,20 +446,12 @@ export default class ScrappingService implements BaseService { throw Error(e.message); } - try { - - // my logic + // escape game by theaters - } catch (error) { - - this.logger.fatal('theater slugs'); - this.logger.fatal((error as Error).message); - - throw Error((error as Error).message); - } + } - public async AllEscapeGame(): Promise { + public async AllEscapeGames(): Promise { let response: AxiosResponse; try { response = await axios.get(`${infos.baseUrl}/escape-game/`); @@ -472,29 +464,44 @@ export default class ScrappingService implements BaseService { throw Error(e.message); } - + const theaterEscapeGame: TheaterEscapeGameModel[] = []; const htmlRoot = cheerio.load(response.data); - const elements = htmlRoot("article"); - let avalaibleTheatherName: String[] = [] ; - htmlRoot("ul.theaters li").each((index ,element) => { - avalaibleTheatherName.push( htmlRoot(element).data("set") as String ); - }); - avalaibleTheatherName.forEach((name) => { - const escapeElement = htmlRoot(`article[data-${name}]`) ; - console.log(escapeElement?.length); - }) - const theaterEscapeGame: TheaterEscapeGameModel = { - name: "", - img: "", - price: 0, - groupSizeMin: 0, - groupSizeMax: 0, - difficulty: 0, - description: "", - minAge: 0, - } + const avalaibleTheatherNames = htmlRoot("ul.theaters li").map((index, element) => htmlRoot(element).data("set") as String); + + avalaibleTheatherNames.each((_, theaterName) => { + + htmlRoot(`article[data-${theaterName}]`).each((index, element) => { + const name = htmlRoot(element).children("h1").text(); + + const e = htmlRoot(element).children(); + + const description = e.find(".info-bloc p").text(); + const difficulty = e.find("li.full").length; + const groupSizeMin = parseInt(e.find(".price").text().match(/Groupe de (\d+)/)?.[1] || "0"); + const groupSizeMax = parseInt(e.find(".price").text().match(/à (\d+) personnes/)?.[1] || "0"); + const price = parseInt(e.find(".price").text().match(/Tarif unique (\d+)/)?.[1] || "0") + const minAge = parseInt(e.find(".age-info").text().match(/\d+/)?.[0] || "0"); + const image = e.find("figure img").attr("src"); + + theaterEscapeGame.push( + { + theaterName: theaterName as string, + name: name, + img: image!, + price: price, + groupSizeMin: groupSizeMin, + groupSizeMax: groupSizeMax, + difficulty: difficulty, + description: description, + minAge: minAge, + } + ); + }); + + + }); return theaterEscapeGame; From 35a846b3e3149bd7926d371c3aa01cc4ffaebc0a Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Wed, 1 Nov 2023 10:17:04 +0000 Subject: [PATCH 3/7] remove escapee route --- src/app.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index f23f3de..014aad7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -84,9 +84,7 @@ class App { this.app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)) this.app.use('/movies', moviesRouter); this.app.use('/theaters', theatersRouter); - this.app.use('/escape', theatersRouter); - } private errorHandler() { From 57e2aa5c33fbb03984cb607a6d1515e9817ba12b Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Wed, 1 Nov 2023 15:17:58 +0000 Subject: [PATCH 4/7] test escape game route --- src/tests/api/theaters-route.test.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/tests/api/theaters-route.test.ts b/src/tests/api/theaters-route.test.ts index 32ee21d..e838a77 100644 --- a/src/tests/api/theaters-route.test.ts +++ b/src/tests/api/theaters-route.test.ts @@ -4,7 +4,7 @@ import request from 'supertest'; describe('Testing theaters routes', () => { const reqApp = request(app); - + test('if /GET is working', async () => { const res = await reqApp.get('/'); @@ -27,8 +27,8 @@ describe('Testing theaters routes', () => { test('if /GET theaters/infos/ is working', async () => { const res = await reqApp.get('/theaters/infos/wologuede'); - - + + expect(res.statusCode).toBe(200); }); @@ -37,7 +37,7 @@ describe('Testing theaters routes', () => { test('if /GET theaters/infos/ with bad theater slug is not working', async () => { const res = await reqApp.get('/theaters/infos/123'); - + expect(res.statusCode).not.toBe(200); }); @@ -45,9 +45,9 @@ describe('Testing theaters routes', () => { test('if /GET theaters/infos/ with bad lang is not working', async () => { - const res = await reqApp.get('/theaters/infos/wologuede?lang=zk'); + const res = await reqApp.get('/theaters/infos/wologuede?lang=zk'); - expect(res.statusCode).not.toBe(200); + expect(res.statusCode).not.toBe(200); }); @@ -60,5 +60,12 @@ describe('Testing theaters routes', () => { }); + test('if /GET theaters/escap-game is working ', async () => { + + const res = await reqApp.get('/theaters/escape-game'); + + expect(res.statusCode).toBe(200); + }) + }) From b9c26e936577e8e7807d2fdc3784ba96f97af7d3 Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Sat, 4 Nov 2023 17:43:33 +0000 Subject: [PATCH 5/7] changing function service allEscapeGame to getAvailableEscapeGameTheaters --- src/controllers/theaters/theaters.controller.ts | 2 +- src/routes/theaters.ts | 2 +- src/tests/services/scrapping.service.test.ts | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/controllers/theaters/theaters.controller.ts b/src/controllers/theaters/theaters.controller.ts index c903330..c2110cd 100644 --- a/src/controllers/theaters/theaters.controller.ts +++ b/src/controllers/theaters/theaters.controller.ts @@ -66,7 +66,7 @@ export default class TheatersController implements BaseController { } } - public async getAllEscapeGames(res: Response): Promise { + public async getAvailableEscapeGameTheaters(res: Response): Promise { try { const data = await this.scrappingService.AllEscapeGames(); return res.status(StatusCodes.OK).json(data); diff --git a/src/routes/theaters.ts b/src/routes/theaters.ts index 780e771..7e40fa3 100644 --- a/src/routes/theaters.ts +++ b/src/routes/theaters.ts @@ -52,7 +52,7 @@ router.get('/escape-game', ExpressValidatorMiddleware, async function (req, res, _next) { - const response = theatersController.getAllEscapeGames(res); + const response = theatersController.getAvailableEscapeGameTheaters(res); return response; } diff --git a/src/tests/services/scrapping.service.test.ts b/src/tests/services/scrapping.service.test.ts index 2f876e9..b4abee1 100644 --- a/src/tests/services/scrapping.service.test.ts +++ b/src/tests/services/scrapping.service.test.ts @@ -199,4 +199,9 @@ describe('Test on Scapping Service', () => { }); }); + + //excape game test + test("if availableMovie with escape game is wroking ", ()=> { + const escapegame = scrappingService.AllEscapeGames + }) }) From a581f7a4a3532d3600af623a8fa26ec7ab198441 Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Sat, 4 Nov 2023 17:45:42 +0000 Subject: [PATCH 6/7] rename the service and controller --- src/controllers/theaters/theaters.controller.ts | 2 +- src/services/scapping/scrapping.servive.ts | 2 +- src/tests/services/scrapping.service.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/theaters/theaters.controller.ts b/src/controllers/theaters/theaters.controller.ts index c2110cd..437b06e 100644 --- a/src/controllers/theaters/theaters.controller.ts +++ b/src/controllers/theaters/theaters.controller.ts @@ -68,7 +68,7 @@ export default class TheatersController implements BaseController { public async getAvailableEscapeGameTheaters(res: Response): Promise { try { - const data = await this.scrappingService.AllEscapeGames(); + const data = await this.scrappingService.AvailableEscapeGameTheaters(); return res.status(StatusCodes.OK).json(data); }catch(error) { diff --git a/src/services/scapping/scrapping.servive.ts b/src/services/scapping/scrapping.servive.ts index 913c728..dcca1f9 100644 --- a/src/services/scapping/scrapping.servive.ts +++ b/src/services/scapping/scrapping.servive.ts @@ -451,7 +451,7 @@ export default class ScrappingService implements BaseService { } - public async AllEscapeGames(): Promise { + public async AvailableEscapeGameTheaters(): Promise { let response: AxiosResponse; try { response = await axios.get(`${infos.baseUrl}/escape-game/`); diff --git a/src/tests/services/scrapping.service.test.ts b/src/tests/services/scrapping.service.test.ts index b4abee1..ddd653c 100644 --- a/src/tests/services/scrapping.service.test.ts +++ b/src/tests/services/scrapping.service.test.ts @@ -202,6 +202,6 @@ describe('Test on Scapping Service', () => { //excape game test test("if availableMovie with escape game is wroking ", ()=> { - const escapegame = scrappingService.AllEscapeGames + const escapegame = scrappingService.AvailableEscapeGameTheaters(); }) }) From 2e5c8b703872b58893099ade0096cde84bb5a5bb Mon Sep 17 00:00:00 2001 From: massahoudou <9324@.Light> Date: Sat, 4 Nov 2023 18:14:41 +0000 Subject: [PATCH 7/7] changing function controller/service naming and test availableTheatersEscapeGame service --- .../theaters/theaters.controller.ts | 4 +- src/docs/swagger-output.json | 310 ------------------ src/routes/theaters.ts | 2 +- src/services/scapping/scrapping.servive.ts | 10 +- src/tests/services/scrapping.service.test.ts | 23 +- 5 files changed, 21 insertions(+), 328 deletions(-) diff --git a/src/controllers/theaters/theaters.controller.ts b/src/controllers/theaters/theaters.controller.ts index 437b06e..35c3e4e 100644 --- a/src/controllers/theaters/theaters.controller.ts +++ b/src/controllers/theaters/theaters.controller.ts @@ -66,9 +66,9 @@ export default class TheatersController implements BaseController { } } - public async getAvailableEscapeGameTheaters(res: Response): Promise { + public async getAvailableTheatersEscapeGame(res: Response): Promise { try { - const data = await this.scrappingService.AvailableEscapeGameTheaters(); + const data = await this.scrappingService.AvailableTheatersEscapeGame(); return res.status(StatusCodes.OK).json(data); }catch(error) { diff --git a/src/docs/swagger-output.json b/src/docs/swagger-output.json index 5da7e6f..899a852 100644 --- a/src/docs/swagger-output.json +++ b/src/docs/swagger-output.json @@ -1244,316 +1244,6 @@ } } } - }, - "/escape/names": { - "get": { - "tags": [ - "Theaters" - ], - "summary": "Fetch all the available theaters name", - "description": "Return an array of strings with the theaters name", - "responses": { - "200": { - "description": "Ok", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/TheaterName" - }, - "xml": { - "name": "main" - } - } - }, - "application/xml": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/TheaterName" - }, - "xml": { - "name": "main" - } - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Bad Request" - }, - "errors": { - "type": "string", - "example": "any" - } - }, - "xml": { - "name": "main" - } - } - }, - "application/xml": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Bad Request" - }, - "errors": { - "type": "string", - "example": "any" - } - }, - "xml": { - "name": "main" - } - } - } - } - } - } - } - }, - "/escape/escape-game": { - "get": { - "description": "", - "responses": { - "default": { - "description": "" - } - } - } - }, - "/escape/infos/{theaterSlug}": { - "get": { - "tags": [ - "Theaters" - ], - "summary": "Fetch informations about a specified theater giving his name", - "description": "Fetch informations about a specified theater giving his name", - "parameters": [ - { - "name": "theaterSlug", - "in": "path", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "lang", - "in": "query", - "description": "The response language", - "schema": { - "type": "string", - "enum": [ - "fr", - "en" - ] - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/TheaterInfos" - } - }, - "application/xml": { - "schema": { - "$ref": "#/components/schemas/TheaterInfos" - } - } - } - }, - "400": { - "description": "Bad request", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Bad request" - }, - "errors": { - "type": "string", - "example": "any" - } - }, - "xml": { - "name": "main" - } - } - }, - "application/xml": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Bad request" - }, - "errors": { - "type": "string", - "example": "any" - } - }, - "xml": { - "name": "main" - } - } - } - } - }, - "404": { - "description": "Not found", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Theater not found" - }, - "errors": { - "type": "array", - "example": [], - "items": {} - } - }, - "xml": { - "name": "main" - } - } - }, - "application/xml": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Theater not found" - }, - "errors": { - "type": "array", - "example": [], - "items": {} - } - }, - "xml": { - "name": "main" - } - } - } - } - }, - "422": { - "description": "Your body was bad formatted", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Your body was bad formatted" - }, - "errors": { - "type": "array", - "items": { - "type": "object", - "properties": { - "type": { - "type": "string", - "example": "field" - }, - "value": { - "type": "string", - "example": "zk" - }, - "msg": { - "type": "string", - "example": "Invalid value" - }, - "path": { - "type": "string", - "example": "lang" - }, - "location": { - "type": "string", - "example": "query" - } - } - } - } - }, - "xml": { - "name": "main" - } - } - }, - "application/xml": { - "schema": { - "type": "object", - "properties": { - "message": { - "type": "string", - "example": "Your body was bad formatted" - }, - "errors": { - "type": "array", - "items": { - "type": "object", - "properties": { - "type": { - "type": "string", - "example": "field" - }, - "value": { - "type": "string", - "example": "zk" - }, - "msg": { - "type": "string", - "example": "Invalid value" - }, - "path": { - "type": "string", - "example": "lang" - }, - "location": { - "type": "string", - "example": "query" - } - } - } - } - }, - "xml": { - "name": "main" - } - } - } - } - } - } - } } }, "components": { diff --git a/src/routes/theaters.ts b/src/routes/theaters.ts index 7e40fa3..a985341 100644 --- a/src/routes/theaters.ts +++ b/src/routes/theaters.ts @@ -52,7 +52,7 @@ router.get('/escape-game', ExpressValidatorMiddleware, async function (req, res, _next) { - const response = theatersController.getAvailableEscapeGameTheaters(res); + const response = theatersController.getAvailableTheatersEscapeGame(res); return response; } diff --git a/src/services/scapping/scrapping.servive.ts b/src/services/scapping/scrapping.servive.ts index dcca1f9..7f3336c 100644 --- a/src/services/scapping/scrapping.servive.ts +++ b/src/services/scapping/scrapping.servive.ts @@ -446,12 +446,12 @@ export default class ScrappingService implements BaseService { throw Error(e.message); } - // escape game by theaters + // escape game by theaters + - } - public async AvailableEscapeGameTheaters(): Promise { + public async AvailableTheatersEscapeGame(): Promise { let response: AxiosResponse; try { response = await axios.get(`${infos.baseUrl}/escape-game/`); @@ -473,9 +473,9 @@ export default class ScrappingService implements BaseService { htmlRoot(`article[data-${theaterName}]`).each((index, element) => { const name = htmlRoot(element).children("h1").text(); - + const e = htmlRoot(element).children(); - + const description = e.find(".info-bloc p").text(); const difficulty = e.find("li.full").length; const groupSizeMin = parseInt(e.find(".price").text().match(/Groupe de (\d+)/)?.[1] || "0"); diff --git a/src/tests/services/scrapping.service.test.ts b/src/tests/services/scrapping.service.test.ts index ddd653c..635fdaa 100644 --- a/src/tests/services/scrapping.service.test.ts +++ b/src/tests/services/scrapping.service.test.ts @@ -12,7 +12,7 @@ describe('Test on Scapping Service', () => { const names = await scrappingService.theatersNames(); expect(names.length).toBeGreaterThan(0); - + const name = names[0]; expect(name.country).toBeDefined(); expect(name.cities.length).toBeGreaterThan(0); @@ -25,7 +25,7 @@ describe('Test on Scapping Service', () => { return scrappingService.theaterMovies('wologuede').then((movies) => { expect(movies.length).toBeGreaterThan(0); - + }); }); @@ -70,7 +70,7 @@ describe('Test on Scapping Service', () => { test('if movieInfoBySlug is not working with bad slug', async () => { return scrappingService.movieInfoBySlug('zkk').then((info) => { - + expect(info).toBeNull(); }); @@ -174,11 +174,11 @@ describe('Test on Scapping Service', () => { expect(movies.length).toBeGreaterThan(0); const movie = movies[0]; - + expect(movie.title).not.toBeNull(); expect(movie.slug).toBeDefined(); expect(movie.img).toBeDefined(); - + }); }); @@ -190,18 +190,21 @@ describe('Test on Scapping Service', () => { expect(movies.length).toBeGreaterThan(0); - const movie = movies[0]; + const movie = movies[0]; expect(movie.title).not.toBeNull(); expect(movie.img).toBeDefined(); expect(movie.slug).toBeDefined(); - + }); }); - //excape game test - test("if availableMovie with escape game is wroking ", ()=> { - const escapegame = scrappingService.AvailableEscapeGameTheaters(); + + test("if available escape game theaters is wroking ", async () => { + return scrappingService.AvailableTheatersEscapeGame().then((theaterEscapeGame => { + expect(theaterEscapeGame.length).toBeGreaterThan(0); + }) + ); }) })