I am trying to write a simple test for a function who call the OVH api.
I don't understand, my sinon.js stub dont "divert" the requestPromised method of ovh api. The sinon.js's stub work differently with a class object ?
My function (myOvhApi.js) :
const ovh = require('ovh')({
endpoint: 'Endpoint',
appKey: 'AppKey',
appSecret: 'appSecret',
consumerKey: 'ConsumerKey'
})
exports.myFunction = async ( ipAdress, subDomain, ovhDynDNSId ) => {
try{
await ovh.requestPromised( 'PUT', `/domain/zone/${zone}/dynHost/record/${ovhDynDNSId}`,
{
'ip': ipAdress,
'subDomain': subDomain
})
} catch (error) {
console.log(error)
}
return true
}
My test:
const ovh = require('ovh')
const myOvhApi = require('myOvhApi')
describe('description', () => {
it('description', async () => {
const zone = 'mydomain.com'
const ovhDynDNSId = '12345'
const ipAdress = '127.0.0.1'
const subDomain = 'subDomain'
sinon.stub( ovh, 'requestPromised' ).returns(true)
const expectation = await myOvhApi.myFunction ( ovhDynDNSId, ipAdress, subDomain )
expect( expectation ).to.equal(true)
})
})
Thank you