describe('QnA class', function() { it('can create a new instance with explicit values as args', function() { let qnatList = {test:123}; let qna = new QnA() qna.qnaList = qnatList assert.deepEqual(qna.qnaList, qnatList) }); it('can create a new instance with no values passed in', function() { assert.deepEqual(new QnA().qnaList, []); }); });
it('Parser correctly parses composite entity definition with semicolon delimiter', function(done){ let luFileContent = `$deviceTemperature : [child1; child2]`; let testCompositeEntity = new hClasses.compositeEntity('deviceTemperature', ['child1', 'child2']); parseFile(luFileContent, false) .then(res => { assert.deepEqual(res.LUISJsonStructure.composites[0], testCompositeEntity); done(); }) .catch(err => done(`Test failed - ${err}`)) });
const assertToLu = async function(srcJSONFile, tgtLUFile) { let testInputFile = await loadJsonFile(srcJSONFile) let testInputJSON = LuisBuilder.fromJson(testInputFile) let testContent = testInputJSON.parseToLuContent(); let verifiedContent = await loadLuFile(tgtLUFile) assert.deepEqual(sanitize(testContent), verifiedContent) }
it('Role definitions are de-duped', function(done){ let luFile = ` @ml s1 r1, r1 `; parseFile.parseFile(luFile) .then(res => { assert.equal(res.LUISJsonStructure.entities[0].roles.length, 1); assert.deepEqual(res.LUISJsonStructure.entities[0].roles, ['r1']); done(); }) .catch(err => done(err)) });
describe('QnA Metadata class', function() { it('can create a new instance with explicit values as args', function() { assert.deepEqual(new QnAMetadata('1', '2'), {name: '1', value: '2'}); }); it('can create a new instance with no values passed in', function() { assert.equal(new QnAMetadata().name, ''); }); });
it('Correctly parses roles with explict type definition in LU files', function(done) { let fileContent = `# getUserName - call me {name:userName} $name: simple`; parseFile(fileContent, false, null) .then(res => { assert.equal(res.LUISJsonStructure.entities[0].name, 'name'); assert.deepEqual(res.LUISJsonStructure.entities[0].roles, ['userName']); done(); }) .catch(err => done(err)); });
describe('closedLists class', function() { it('can create a new instance with no values passed in', function() { assert.equal(new hClasses.closedLists().name , ''); }); it('can create a new instance with explicit values as args', function() { assert.deepEqual(new hClasses.closedLists('1', '2', '3'), {name: '1', subLists: '2', roles: '3'}); }); });
it('correctly de-dupes when multiple regex entities with same name and pattern are defined in a lu file', function(done){ let luFileContent = `$test:/hrf-[0-9]{6}/ $test:/hrf-[0-9]{6}/`; let regexEntity = new hClasses.regExEntity('test', 'hrf-[0-9]{6}'); parseFile(luFileContent, false) .then(res => { assert.equal(res.LUISJsonStructure.regex_entities.length, 1); assert.deepEqual(res.LUISJsonStructure.regex_entities[0], regexEntity); done(); }) .catch(err => done(`Test failed - ${JSON.stringify(err, null, 2)}`)) });
describe('readerObj class', function(){ it('can create a new instance with explicit values as args', function() { assert.deepEqual(new hClasses.readerObject('1', '2'), {sourceFile: '1', model: '2'}); }); it('can create a new instance with no values passed in', function() { assert.equal(new hClasses.readerObject().sourceFile, ''); }); });
it ('roles can have spaces in them', function(done) { let lufile = ` @ ml "entity 1" hasRoles "role 1", "role 2" ` parseFile.parseFile(lufile) .then(res => { assert.deepEqual(res.LUISJsonStructure.entities[0].roles, ["role 1", "role 2"]); done() }) .catch(err => done(err)) })
describe('pattern class', function() { it('can create a new instance with no values passed in', function() { assert.equal(new hClasses.pattern().pattern, ''); }); it('can create a new instance with explicit values as args', function() { assert.deepEqual(new hClasses.pattern('1', '2'), {pattern: '1', intent: '2'}); }); });
describe('intent class', function(){ it('can create a new instance with explicit values as args', function() { assert.deepEqual(new hClasses.intent('1', '2'), {intent: '1', utterances: '2'}); }); it('can create a new instance with no values passed in', function() { assert.equal(new hClasses.intent().intent, ''); }); });
it('are parsed correctly when a valid regex pattern is provided', function(done){ let luFileContent = `$HRF-number:/hrf-[0-9]{6}/`; let regexEntity = new hClasses.regExEntity('HRF-number', 'hrf-[0-9]{6}'); parseFile(luFileContent, false) .then(res => { assert.deepEqual(res.LUISJsonStructure.regex_entities[0], regexEntity); done(); }) .catch(err => done(`Test failed - ${err}`)) });
it('Corretly parses simple roles in LU files', function(done){ let fileContent = `# getUserName - call me {name:userName}`; parseFile(fileContent, false, null) .then(res => { assert.equal(res.LUISJsonStructure.patternAnyEntities[0].name, 'name'); assert.deepEqual(res.LUISJsonStructure.patternAnyEntities[0].roles, ['userName']); done(); }) .catch(err => done(err)); });
it('Parser correctly parses composite entity definition with comma delimiter', function(done){ let luFileContent = `$deviceTemperature : [child1, child2]`; let testCompositeEntity = new hClasses.compositeEntity('deviceTemperature', ['child1', 'child2']); parseFile(luFileContent, false) .then(res => { assert.deepEqual(res.LUISJsonStructure.composites[0], testCompositeEntity); done(); }) .catch(err => done(`Test failed - ${err}`)) });