Skip to content

Commit

Permalink
Test for setting cookie values
Browse files Browse the repository at this point in the history
  • Loading branch information
esvitaly committed Sep 19, 2018
1 parent 43929cf commit 1114c43
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -42,6 +42,7 @@
"eslint-plugin-import": "^2.7.0",
"mocha": "^4.0.1",
"nodemon": "^1.12.1",
"supertest": "^3.0.0"
"supertest": "^3.0.0",
"pdf2json": "^1.1.7"
}
}
45 changes: 45 additions & 0 deletions test/test-all.js
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
const request = require('supertest');
const BPromise = require('bluebird');
const { getResource } = require('./util');
const PDFParser = require('pdf2json');
const createApp = require('../src/app');

const DEBUG = false;
Expand Down Expand Up @@ -129,4 +130,48 @@ describe('POST /api/render', () => {
chai.expect(length).to.be.above(30 * 1024 * 1);
})
);

it('cookies should exist on the page', () =>
request(app)
.post('/api/render')
.send({
url: 'http://www.html-kit.com/tools/cookietester/',
cookies:
[{
name: 'url-to-pdf-test',
value: 'test successful',
domain: 'www.html-kit.com',
}, {
name: 'url-to-pdf-test-2',
value: 'test successful 2',
domain: 'www.html-kit.com',
}],
})
.set('Connection', 'keep-alive')
.set('content-type', 'application/json')
.expect(200)
.expect('content-type', 'application/pdf')
.then((response) => {
if (DEBUG) {
console.log(response.headers);
console.log(response.body);
fs.writeFileSync('out.pdf', response.body, { encoding: null });
}

const pdfParser = new PDFParser(this, 1);

pdfParser.on('pdfParser_dataError', (errData) => {
console.error(errData.parserError);
chai.fail(errData.parserError);
});

pdfParser.on('pdfParser_dataReady', () => {
const rawContent = pdfParser.getRawTextContent();
chai.expect(rawContent.indexOf('Number of cookies received: 2')).to.be.above(0);
chai.expect(rawContent.indexOf('Cookie named "url­to­pdf­test"')).to.be.above(0);
chai.expect(rawContent.indexOf('Cookie named "url­to­pdf­test­2"')).to.be.above(0);
if (DEBUG) fs.writeFileSync('./content.txt', rawContent);
});
})
);
});

0 comments on commit 1114c43

Please sign in to comment.