Files
graphql-api-js/src/__test__/db_generator/invoices.js
T
Arwid ThornströmandGitHub c92482777d P5-7496: orders tests (#3)
* P5-7495: added more db data and more designer tests

* P5-7496: rebuild for sql export, added better test control values

* changed order rows - edge from int to string

* added tests for designer order rows

* remove sql inserts

* Some cleanup and moving files

* package

* removed comments

* added base sql files to pass tests on github CI
2021-07-02 11:17:59 +02:00

40 lines
966 B
JavaScript

import _ from 'lodash';
import { io, saveFromTemplate, padNum } from './common.js';
// INSERT INTO public.invoices (id, inserted, order_id, invoice_date, invoice_sent) VALUES (DEFAULT, '2019-06-12T16:16:50.784Z', 4, '2019-06-12', 1);
const keys = {
id: 'DEFAULT',
inserted: 'DEFAULT',
order_id: null,
invoice_date: '',
invoice_sent: '',
};
const inserts = [];
const N = 10;
for (const id of [...Array(N + 1).keys()].slice(1)) {
const now = new Date();
const key = Object.assign({}, keys, {
order_id: id,
invoice_date: `'${now.getFullYear()}-${padNum(now.getMonth())}-${padNum(
now.getDay(),
)}'`,
invoice_sent: io(),
});
const insertString = `INSERT INTO public.invoices (id, inserted, order_id, invoice_date, invoice_sent) VALUES (${Object.values(
key,
).join(', ')});`;
inserts.push(insertString);
}
saveFromTemplate(
'templates/invoices.sql',
'../db/data/invoices.sql',
'{x}',
inserts.join('\n'),
);