I have a function stored in a separate file which has a call to a graphql endpoint.
I am trying to call this function and return an id (which is returned) - however, I am getting an warning that I am using .end and .done
The function:
module.exports = {
addThing: async function (title, extRef, done) {
const basicAddCreative = `mutation { ...}`
let the_id = await request
.post("/graphql")
.send({
query: basicAddCreative
})
.set("Accept", "application/json")
.expect(200)
.end((err, res) => {
if (err) return done(err)
return res.body.data.id
})
return the_id
}
}
And this is called (in a different file)
let cId = helpers.addThing('fnTest', 'fnTest', done)
cId.then(i => console.log(i))
And then when I run this the test I have fails for : .end() was called twice. This is not supported in superagent And then I see: Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises.
Can anyone shed light on how I could fix the above? Specifically, if I am using supertest with chai, I need to use the .end (or supertest will mark the query as fail for timingout) - and I need to use .then to get the return value. So, how is this possible?