Skip to content

Commit

Permalink
feat: #60: obtain VAST XML for a specific session (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
birme authored Oct 7, 2021
1 parent d56150e commit fd453c0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
46 changes: 46 additions & 0 deletions api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,25 @@ const schemas = {
},
security: [{ apiKey: [] }],
},
"GET/sessions/:sessionId/vast": {
description:
"Gets the VAST XML created for a specific session",
tags: ["sessions"],
params: {
sessionId: {
type: "string",
description: "The ID for the session. ",
},
},
response: {
200: {
description: "VAST XML",
type: "string",
},

404: BadRequestSchema("Session with ID: 'xxx-xxx-xxx-xxx' was not found"),
},
},
"DELETE/sessions/:sessionId": {
description: "Deletes the given session",
tags: ["sessions"],
Expand Down Expand Up @@ -662,6 +681,33 @@ module.exports = (fastify, opt, next) => {
}
);

fastify.get(
"/sessions/:sessionId/vast",
{ schema: schemas["GET/sessions/:sessionId/vast"] },
async (req, reply) => {
const sessionId = req.params.sessionId;
try {
// Check if session exists.
const session = await DBAdapter.getSession(sessionId);
if (!session) {
reply.code(404).send({
message: `Session with ID: '${sessionId}' was not found`,
});
} else {
vast_xml = session.getVastXml();
reply.headers({
"Content-Type": "application/xml;charset=UTF-8"
})
reply.code(200).send(vast_xml);
}
} catch (exc) {
console.error(exc);
logger.error(exc, { label: req.headers['host'], sessionId: sessionId });
reply.code(500).send({ message: exc.message });
}
}
)

// Users - routes
fastify.get(
"/users/:userId",
Expand Down
26 changes: 24 additions & 2 deletions test/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ describe(" MY ROUTES", () => {
});
});

// test 7
describe("GET->SESSIONS/:sessionId/events", () => {
// test 7
describe("GET->SESSIONS/:sessionId/events", () => {
let reply;
before((done) => {
chai
Expand Down Expand Up @@ -437,4 +437,26 @@ describe(" MY ROUTES", () => {
});
});
});
// test 8
describe("GET->SESSIONS/:sessionId/vast", () => {
let reply;
before((done) => {
chai
.request(SERVER_URL)
.get("/api/v1/sessions/" + SID + "/vast")
.end((err, res) => {
if (err) {
done(err);
}
reply = res;
done();
});
});
it("should be content-type: application/xml ", () => {
reply.should.have.header(
"content-type",
"application/xml;charset=UTF-8"
);
});
});
});

0 comments on commit fd453c0

Please sign in to comment.