diff --git a/docs/nfc-server/Generate activation label.yml b/docs/nfc-server/Generate activation label.yml index 4e35200..dc8f2c5 100644 --- a/docs/nfc-server/Generate activation label.yml +++ b/docs/nfc-server/Generate activation label.yml @@ -10,11 +10,25 @@ http: type: json data: |- { - "cardId": "", + "card_id": "1234", "override": false } auth: inherit +runtime: + scripts: + - type: tests + code: |- + test("Should return 200", () => { + const body = res.getBody() + expect(res.getStatus()).to.equal(200) + }) + + test("Body should include the label", () => { + const body = res.getBody() + expect(body.label).to.be.defined() + )} + settings: encodeUrl: true timeout: 0 @@ -31,7 +45,7 @@ examples: type: json data: |- { - "cardId": "", + "card_id": "", "override": false } response: @@ -58,7 +72,7 @@ examples: type: json data: |- { - "cardId": "", + "card_id": "", "override": false } response: @@ -85,7 +99,7 @@ examples: type: json data: |- { - "cardId": "", + "card_id": "", "override": false } response: @@ -93,4 +107,7 @@ examples: statusText: Internal Server Error body: type: text - data: "" + data: |- + { + "error": "" + } diff --git a/docs/nfc-server/Health check.yml b/docs/nfc-server/Health check.yml index 172c942..39d5bd9 100644 --- a/docs/nfc-server/Health check.yml +++ b/docs/nfc-server/Health check.yml @@ -8,6 +8,22 @@ http: url: "{{baseUrl}}/health" auth: inherit +runtime: + scripts: + - type: tests + code: |- + test("Should return 200", () => { + const body = res.getBody() + expect(res.getStatus()).to.equal(200) + }) + + test("Body should be ok:true", () => { + const body = res.getBody() + expect(body).to.eql({ + ok:true + }) + }) + settings: encodeUrl: true timeout: 0 diff --git a/docs/nfc-server/environments/Local development server.yml b/docs/nfc-server/environments/Local.yml similarity index 84% rename from docs/nfc-server/environments/Local development server.yml rename to docs/nfc-server/environments/Local.yml index 4742592..95e8b09 100644 --- a/docs/nfc-server/environments/Local development server.yml +++ b/docs/nfc-server/environments/Local.yml @@ -1,4 +1,5 @@ name: Local development server +color: "#2E8A54" variables: - name: baseUrl value: http://localhost:3000 diff --git a/src/aplication/Nfc.controller.ts b/src/aplication/Nfc.controller.ts index 8527a3f..6eba4c5 100644 --- a/src/aplication/Nfc.controller.ts +++ b/src/aplication/Nfc.controller.ts @@ -38,7 +38,7 @@ export class NfcController { return 1; } - + res.status(200).json(useCaseRes) return 0; } diff --git a/src/aplication/Nfc.usecases.ts b/src/aplication/Nfc.usecases.ts index 28cefdc..75b4003 100644 --- a/src/aplication/Nfc.usecases.ts +++ b/src/aplication/Nfc.usecases.ts @@ -9,12 +9,12 @@ export class NfcUsecases { private ctx: ServerContext; private nfcRepository: NfcRepository; - constructor( + constructor(args: { serverContext: ServerContext, nfcRepository: NfcRepository - ) { - this.ctx = serverContext - this.nfcRepository = nfcRepository + }) { + this.ctx = args.serverContext + this.nfcRepository = args.nfcRepository } private getRandomDayOffset() { diff --git a/src/aplication/validators.ts b/src/aplication/validators.ts index e7b2903..548cb6e 100644 --- a/src/aplication/validators.ts +++ b/src/aplication/validators.ts @@ -1,9 +1,9 @@ import { BodyValidator, type Validator } from "./BodyValidator.js"; -const cardIdExists: Validator<{ cardId?: string }> = { - field: "cardId", - validationFunc: (body) => body.cardId != undefined, - errorMsg: "El campo cardId esta undefined" +const cardIdExists: Validator<{ card_id?: string }> = { + field: "card_id", + validationFunc: (body) => body.card_id != undefined, + errorMsg: "El campo card_id esta undefined" } export const baseValidator = new BodyValidator([cardIdExists]) diff --git a/src/main.ts b/src/main.ts index 92ce9b7..64aee47 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,23 +6,46 @@ import { env } from './config/env.config.js'; import type { ServerContext } from 'domain/ServerContext.js'; import { httpclient } from 'config/httpclient.config.js'; import { pgClient } from 'config/pgclient.config.js'; +import { NfcController } from 'aplication/Nfc.controller.js'; +import { NfcUsecases } from 'aplication/Nfc.usecases.js'; +import { NfcRepository } from 'infrastructure/Nfc.repository.js'; const PORT = env.PORT const HOSTNAME = env.HOST assert(HOSTNAME != undefined) +// Instancias de las dependencias + const serverContext: ServerContext = { HttpClient: httpclient, PostgresClient: pgClient } +const nfcRepository = new NfcRepository(serverContext) + +const nfcUsecases = new NfcUsecases({ + serverContext, + nfcRepository +}) + +const ncfControllers = new NfcController({ + serverContext, + nfcUsecases +}) + +// Rutas + const router = Router(); router.get("/health", (req: Request, res: Response) => { res.json({ ok: true }) }) +router.post("/nfc/generate", ncfControllers.generateActivationTag()) + +// Inicio de express + const app = express(); app.use(express.json());