@ibm-adw/skill-toolkit
Version:
Developing your own skills with IBM Automation Digital Worker Skill Toolkit
46 lines (32 loc) • 1.07 kB
JavaScript
// skill-api.test.js
/* eslint-env jest */
;
const skill = require('../skill-api');
const outputSchema = require('../skill-config')['outputSchema'];
const Ajv = require('ajv');
const ajv = new Ajv();
const context = {
logger: {
trace: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn()
}
};
const config = {};
const assertValidOutput = (result, configuration) => {
// Test result is a valid JSON according to outputSchema(config)
ajv.validate(outputSchema(configuration), result);
expect(ajv.errors).toBe(null);
};
describe('SKILL RUNTIME - Basic Tests', () => {
test('Checking an incorrect input is throwing', () => {
expect(() => skill(config)(undefined, context)).toThrow('NO_INPUT');
});
test('Checking a correct input logs in context', async () => {
const result = await skill(config)('input', context);
expect(context.logger.info).toHaveBeenCalledTimes(2);
assertValidOutput(result, config);
});
});