|
| 1 | +/* global describe, it */ |
| 2 | +import chai from 'chai' |
| 3 | +import fs from 'fs' |
| 4 | +import graphlib from 'graphlib' |
| 5 | +import * as api from '../src/api' |
| 6 | + |
| 7 | +var expect = chai.expect |
| 8 | + |
| 9 | +describe('Typgins', () => { |
| 10 | + |
| 11 | + it('can validate typings', () => { |
| 12 | + expect(api.validateTypings({number: 'int', bool: 'bool', string: 'string'})).to.be.true |
| 13 | + expect(api.validateTypings({bool: 'bool', string: 'string'})).to.be.false |
| 14 | + expect(api.validateTypings({int: 'int', bool: 'bool', string: 'string'})).to.be.false |
| 15 | + expect(api.validateTypings({number: 'int', bool: null, string: 'string'})).to.be.false |
| 16 | + }) |
| 17 | + |
| 18 | + it('converts every generic port-type into a concrete one', () => { |
| 19 | + var graph = graphlib.json.read(JSON.parse(fs.readFileSync('test/fixtures/add.json', 'utf8'))) |
| 20 | + var newGraph = api.applyTypings(graph, {number: 'a', bool: 'b', string: 'c'}) |
| 21 | + expect(newGraph.node('a').inputPorts['s1']).to.equal('a') |
| 22 | + expect(newGraph.node('a').inputPorts['s2']).to.equal('b') |
| 23 | + expect(newGraph.node('a').outputPorts['sum']).to.equal('c') |
| 24 | + }) |
| 25 | + |
| 26 | + it('fails to apply invalid typings', () => { |
| 27 | + expect(() => api.applyTypings({}, {numba: 'a', bool: 'b', string: 'c'})) |
| 28 | + .to.throw(Error) |
| 29 | + }) |
| 30 | +}) |
0 commit comments