UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

61 lines 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AtomResponse = void 0; const xmlresponse_1 = require("./xmlresponse"); const cheerio = require("cheerio"); const validMimeTypes = ["application/atom+xml", "text/xml", "text/atom+xml"]; class AtomResponse extends xmlresponse_1.XmlResponse { get responseTypeName() { return "Atom"; } get responseType() { return "atom"; } init(httpResponse) { var _a; super.init(httpResponse); this.context.assert(this.statusCode).between(200, 299); const mimeType = (_a = String(this.header("Content-Type").$) .split(";") .shift()) === null || _a === void 0 ? void 0 : _a.trim(); this.context .assert(`Mime Type is valid for Atom (${validMimeTypes.join(", ")})`, mimeType) .in(validMimeTypes); this.context .assert("Has required Atom fields", this.hasRequiredAtomFields()) .equals(true); } hasRequiredAtomFields() { const feed = this.cheerio("feed"); if (feed.length !== 1) { return false; } const channelId = feed.children("id"); const channelTitle = feed.children("title"); const channelUpdated = feed.children("updated"); if (channelId.length !== 1 || channelTitle.length != 1 || channelUpdated.length != 1) { return false; } const entries = feed.children("entry"); if (entries.length > 0) { let allItemsAreValid = true; entries.each((i, entry) => { const id = cheerio(entry).children("id"); const title = cheerio(entry).children("title"); const updated = cheerio(entry).children("updated"); if (id.length !== 1 || title.length !== 1 || updated.length !== 1) { allItemsAreValid = false; return false; } }); if (!allItemsAreValid) { return false; } } return true; } } exports.AtomResponse = AtomResponse; //# sourceMappingURL=atomresponse.js.map