REST Service for POPCORN - ILIAS
alex
3 hours ago edcf6061e5efbe1b60bc1d17ff4bbe83ae866a09
adding route /api/ping
1 files modified
1 files added
52 ■■■■■ changed files
app.js 11 ●●●●● patch | view | raw | blame | history
test/testApiPing.js 41 ●●●●● patch | view | raw | blame | history
app.js
@@ -337,6 +337,17 @@
      }
   })
   /////// system ////////////////////////////////////////////////////////////////
   .post("/api/ping", async function (req, res) {
      try {
         const res2 = await libIlias.ping()
         return res.send(res2)
      } catch (err) {
         console.error(err)
         return res.code(500).send({status: "error", error: err.toString()})
      }
   })
/////// STATIC / SPA ////////////////////////////////////////////////////////////////
test/testApiPing.js
New file
@@ -0,0 +1,41 @@
const expect = require("chai").expect
const settings = require("../settings")
/////////////////////////////////////////////////////////////////////////
function getUrl(ref_id) {
    return `http://localhost:${settings.port}/api/ping?token=${settings.authtoken}`
}
const ref_id = 595
describe("using the API", function () {
    describe("the Route POST /api/ping", function () {
        it("should return an answer from php component", async function () {
            const url = getUrl(ref_id)
            console.log(url)
            const res = await fetch(url, {
                method: "POST",
                body: JSON.stringify({}),
                headers: {
                    'Content-Type': 'application/json', // Indicate JSON data
                },
            })
            // console.log(res)
            const data = await res.json()
            console.log(data)
            expect(data).to.be.a("object")
            expect(data.status).to.equal("ok")
            expect(data.msg).to.equal("pong")
        })
    })
})
/////////////////////////////////////////////////////////////////////////