Instantly share code, notes, and snippets.

Embed
What would you like to do?
get_invoices_html.js
/* eslint prefer-arrow-callback: 0 */
import expect from 'expect';
import moment from 'moment';
import timekeeper from 'timekeeper';
import beautify from 'js-beautify';
import * as apiUtils from '../../../helpers/api';
import * as serverUtils from '../../../helpers/server';
import * as mongoUtils from '../../../helpers/mongo';
import { invoicesFixtures } from './fixtures/get_invoice_html';
describe('[integration/api] GET /v2/invoices/{invoiceId}.html', function() {
serverUtils.startServer();
serverUtils.stopServer();
// freezing the time because invoices are generated with a timestamps
// and snapshots should be updated every day..
before(function() {
timekeeper.freeze(moment('2018-01-17').toDate());
});
after(function() {
timekeeper.reset();
});
const beautifyHtml = html =>
beautify.html(html, {
indent_size: 2,
indent_inner_html: true,
});
const cleanupMongo = function() {
const fixtures = [{ collection: 'invoices', data: invoicesFixtures }];
return Promise.resolve()
.then(mongoUtils.cleanV2({ mongo: this.mongo, fixtures }))
.then(mongoUtils.loadFixturesV2({ mongo: this.mongo, fixtures }));
};
before('load mongo fixtures', cleanupMongo);
const invoiceHtmlTest = (id, lang) => () => {
before(
'call api',
apiUtils.callApiV2({
method: 'GET',
url: `/v2/invoices/${id}.html?lang=${lang}`,
}),
);
it('should respond with HTTP 200 (OK)', function() {
expect(this.response.statusCode).toEqual(200);
});
it(`should have correct html (${lang})`, function() {
expect(beautifyHtml(this.response.payload)).toMatchSnapshot(this);
});
};
describe('germany', function() {
describe('invoice', function() {
describe('no VAT registered', function() {
describe('de', invoiceHtmlTest('1', 'de'));
describe('en', invoiceHtmlTest('1', 'en'));
});
describe('VAT registered', function() {
describe('de', invoiceHtmlTest('2', 'de'));
describe('en', invoiceHtmlTest('2', 'en'));
});
});
describe('credit note', function() {
describe('no VAT registered', function() {
describe('de', invoiceHtmlTest('3', 'de'));
describe('en', invoiceHtmlTest('3', 'en'));
});
describe('VAT registered', function() {
describe('de', invoiceHtmlTest('4', 'de'));
describe('en', invoiceHtmlTest('4', 'en'));
});
});
});
describe('europe', function() {
describe('invoice', function() {
describe('no VAT registered', function() {
describe('de', invoiceHtmlTest('5', 'de'));
describe('en', invoiceHtmlTest('5', 'en'));
});
describe('VAT registered', function() {
describe('de', invoiceHtmlTest('6', 'de'));
describe('en', invoiceHtmlTest('6', 'en'));
});
});
describe('credit note', function() {
describe('no VAT registered', function() {
describe('de', invoiceHtmlTest('7', 'de'));
describe('en', invoiceHtmlTest('7', 'en'));
});
describe('VAT registered', function() {
describe('de', invoiceHtmlTest('8', 'de'));
describe('en', invoiceHtmlTest('8', 'en'));
});
});
});
describe('rest of the world', function() {
describe('invoice', function() {
describe('no VAT registered', function() {
describe('de', invoiceHtmlTest('9', 'de'));
describe('en', invoiceHtmlTest('9', 'en'));
});
describe('VAT registered', function() {
describe('de', invoiceHtmlTest('10', 'de'));
describe('en', invoiceHtmlTest('10', 'en'));
});
});
describe('credit note', function() {
describe('no VAT registered', function() {
describe('de', invoiceHtmlTest('11', 'de'));
describe('en', invoiceHtmlTest('11', 'en'));
});
describe('VAT registered', function() {
describe('de', invoiceHtmlTest('12', 'de'));
describe('en', invoiceHtmlTest('12', 'en'));
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment