Skip to content

Commit

Permalink
Add test for MappingsApiProvider (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed May 11, 2020
1 parent 92799ac commit 330bd80
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/providers/mappings-api-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const MappingsApiProvider = require("../../providers/mappings-api-provider")
const assert = require("assert")
const MockAdapter = require("axios-mock-adapter")
const errors = require("../../errors")
const jskos = require("jskos-tools")

const api = {
mappings: "test:/mappings",
Expand Down Expand Up @@ -86,6 +87,30 @@ describe("MappingsApiProvider", () => {
assert(wasError)
})

it("should perform posting a mapping correctly", (done) => {
const mappingToPost = {}
const mapping = jskos.addMappingIdentifiers(mappingToPost)
mock.onPost().reply(config => {
assert.equal(config.url, api.mappings)
assert.deepEqual(JSON.parse(config.data), mapping)

done()
return [200, {}]
})
registry.postMapping({ mapping })
})

it("should throw an error when calling postMapping without mapping", async () => {
let wasError = false
try {
await registry.postMapping()
} catch(error) {
wasError = true
assert(error instanceof errors.InvalidOrMissingParameterError)
}
assert(wasError)
})

/***
* TODO: Implement more test.
*
Expand Down

0 comments on commit 330bd80

Please sign in to comment.