1 | "use strict";
|
2 | let helpers = require("../src/lib/helpers.js");
|
3 | let chai = require("chai");
|
4 | let pd = require("pretty-data").pd;
|
5 | let expect = chai.expect;
|
6 | let assert = chai.assert;
|
7 | let chaiXml = require("chai-xml");
|
8 | chai.use(chaiXml);
|
9 |
|
10 | describe("Helpers", function() {
|
11 | it("should return json data", function(done) {
|
12 | helpers
|
13 | .getJSON("https://419webdev.site/titles")
|
14 | .then(function(data) {
|
15 | expect(data).to.deep.equal(
|
16 | '[{"zFile":"zork.z5"},{"zFile":"zork2.z5"},{"zFile":"zork3.z5"},{"zFile":"ztuu.z5"}]'
|
17 | );
|
18 | done();
|
19 | })
|
20 | .catch();
|
21 | });
|
22 | it("should return valid xml data", function(done) {
|
23 | helpers
|
24 | .getXML("https://www.w3schools.com/xml/note.xml")
|
25 | .then(function(data) {
|
26 | expect(data).xml.to.be.valid();
|
27 | done();
|
28 | })
|
29 | .catch();
|
30 | });
|
31 | it("should throw error if date is not valid validate_year", function() {
|
32 | assert.throws(function() {
|
33 | helpers.validate_year("201-12-03");
|
34 | }, "Incorrect date format, should be YYYY");
|
35 | });
|
36 | it("should return date validate_year", function() {
|
37 | let r = helpers.validate_year("2017");
|
38 | assert.equal(r.toString(), "2017");
|
39 | });
|
40 | it("should throw error if iso date is not valid", function() {
|
41 | assert.throws(function() {
|
42 | helpers.validate_iso8601("2014-01-01T23:59");
|
43 | }, "Incorrect date format, should be YYYY-MM-DDTHH:mm:ss");
|
44 | });
|
45 | it("should return date validate_iso8601", function() {
|
46 | let r = helpers.validate_iso8601("2014-01-01T23:59:59");
|
47 | assert.equal(r.toString(), "2014-01-01T23:59:59");
|
48 | });
|
49 | it("should throw error if date is not valid", function() {
|
50 | assert.throws(function() {
|
51 | helpers.vali_date("201-12-03");
|
52 | }, "Incorrect date format, should be YYYY");
|
53 | });
|
54 |
|
55 | it("should reformat date", function() {
|
56 | let r = helpers.vali_date("2017-12-03");
|
57 | assert.equal(r.toString(), "2017/12/03");
|
58 | });
|
59 | it("should return NASA_API_KEY", function() {
|
60 | let r = helpers.nasa_api_key();
|
61 | assert.equal(r.toString(), "TxpAbzBJkgazWhEkL2WIyZW2rsnEFx2Ns7Wmrey0");
|
62 | });
|
63 | });
|