Specific Tests - Unit
- 02 Dec 2022
-
DarkLight
-
PDF
Specific Tests - Unit
- Updated on 02 Dec 2022
-
DarkLight
-
PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
The Adapter Builder will create tests for every API method created in the adapter.js file. The following tests are specific to the adapter and can be customized as needed to enhance or extend testing.
First Test
This will test that the adapter API method exists.
describe('#createTenant', () => {
it('should have a createTenant function', (done) => {
try {
assert.equal(true, typeof a.createTenant === 'function’);
done();
} catch (error) {
log.error(`Test Failure: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
Second Test
This will test an error when a required parameter has not been provided.
runErrorAsserts: This is a private function that tests that the appropriate error object has been received.
describe('#createTenant', () => {
it('should error if - missing tenant name', (done) => {
try {
a.createTenant(null, null, (data, error) => {
try {
const displayE = 'tenantName is required’;
runErrorAsserts(data, error, 'AD.300', 'test-apic-adapter-createTenant', displayE);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
Third Test
This will test for Ajv failures when translating data. This can be a missing field or a field that has an invalid value (not the correct data type).
describe('#createDevice', () => {
it('should error on create a device - no name', (done) => {
try {
const device = { ipAddress: '10.10.10.1' };
a.createDevice(device, (data, error) => {
try {
const displayE = 'Schema validation failed on should have required property \'.name\’’;
runErrorAsserts(data, error, 'AD.312', 'Test-sevone-translatorUtil-buildJSONEntity', displayE);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
Was this article helpful?