|
| 1 | +const { expect } = require('chai'); |
| 2 | +const { MockRuntime } = require('@axway/api-builder-test-utils'); |
| 3 | +const getPlugin = require('../src'); |
| 4 | + |
| 5 | +describe('flow-node pdf', () => { |
| 6 | + let plugin; |
| 7 | + let flowNode; |
| 8 | + beforeEach(async () => { |
| 9 | + plugin = await MockRuntime.loadPlugin(getPlugin); |
| 10 | + plugin.setOptions({ |
| 11 | + validateInputs: true, |
| 12 | + validateOutputs: true |
| 13 | + }); |
| 14 | + flowNode = plugin.getFlowNode('pdf'); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('#constructor', () => { |
| 18 | + it('should define flow-nodes', () => { |
| 19 | + expect(plugin).to.be.a('object'); |
| 20 | + expect(plugin.getFlowNodeIds()).to.deep.equal([ 'pdf' ]); |
| 21 | + expect(flowNode).to.be.a('object'); |
| 22 | + |
| 23 | + // Ensure the flow-node matches the spec |
| 24 | + expect(flowNode.name).to.equal('PDF'); |
| 25 | + expect(flowNode.description) |
| 26 | + .to.equal('PDF functions.'); |
| 27 | + expect(flowNode.icon).to.be.a('string'); |
| 28 | + expect(flowNode.getMethods()).to.deep.equal([ |
| 29 | + 'generatePDFFromMarkdown', |
| 30 | + 'parsePDF' |
| 31 | + ]); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should define valid flow-nodes', () => { |
| 35 | + // if this is invalid, it will throw and fail |
| 36 | + plugin.validate(); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('#generatePDFFromMarkdown', () => { |
| 41 | + it('should error when missing required parameter', async () => { |
| 42 | + // Disable automatic input validation (we want the action to handle this) |
| 43 | + plugin.setOptions({ validateInputs: false }); |
| 44 | + |
| 45 | + // Invoke method with a null and check error. |
| 46 | + const { value, output } = await flowNode.generatePDFFromMarkdown({ |
| 47 | + markdown: null |
| 48 | + }); |
| 49 | + |
| 50 | + expect(value).to.be.instanceOf(Error) |
| 51 | + .and.to.have.property('message', 'Missing required parameter: markdown'); |
| 52 | + expect(output).to.equal('error'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should succeed with valid argument', async () => { |
| 56 | + const { |
| 57 | + value, |
| 58 | + output |
| 59 | + } = await flowNode.generatePDFFromMarkdown({ |
| 60 | + markdown: '# Hello' |
| 61 | + }); |
| 62 | + expect(value).to.match(/^%PDF-1.4/); |
| 63 | + expect(output).to.equal('next'); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe('#parsePDF', () => { |
| 68 | + it('should error when missing required parameter', async () => { |
| 69 | + // Disable automatic input validation (we want the action to handle this) |
| 70 | + plugin.setOptions({ validateInputs: false }); |
| 71 | + |
| 72 | + // Invoke method with a null and check error. |
| 73 | + const { value, output } = await flowNode.parsePDF({ |
| 74 | + data: null |
| 75 | + }); |
| 76 | + |
| 77 | + expect(value).to.be.instanceOf(Error) |
| 78 | + .and.to.have.property('message', 'Missing required parameter: data'); |
| 79 | + expect(output).to.equal('error'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should succeed with valid argument', async () => { |
| 83 | + const { |
| 84 | + value: data |
| 85 | + } = await flowNode.generatePDFFromMarkdown({ |
| 86 | + markdown: '# Hello' |
| 87 | + }); |
| 88 | + |
| 89 | + const { |
| 90 | + value, |
| 91 | + output |
| 92 | + } = await flowNode.parsePDF({ |
| 93 | + data |
| 94 | + }); |
| 95 | + expect(value).to.deep.include({ |
| 96 | + pages: 1, |
| 97 | + pagesRendered: 1, |
| 98 | + version: '1.10.100', |
| 99 | + metadata: null, |
| 100 | + text: '\n\nHello', |
| 101 | + version: '1.10.100' |
| 102 | + }); |
| 103 | + // this is a date |
| 104 | + expect(value.info).to.have.property('created'); |
| 105 | + // this is a date |
| 106 | + expect(value.info).to.have.property('modified'); |
| 107 | + expect(value.info).to.deep.include({ |
| 108 | + version: '1.4', |
| 109 | + isAcroFormPresent: false, |
| 110 | + isXFAPresent: false, |
| 111 | + creator: 'Chromium', |
| 112 | + producer: 'Skia/PDF m100' |
| 113 | + }) |
| 114 | + expect(output).to.equal('next'); |
| 115 | + }); |
| 116 | + }); |
| 117 | +}); |
0 commit comments