declastruct-stripe-sdk
Version:
declarative control of stripe constructs, via declastruct
105 lines • 4.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uni_time_1 = require("@ehmpathy/uni-time");
const test_fns_1 = require("test-fns");
const uuid_fns_1 = require("uuid-fns");
const getStripeCredentials_1 = require("../../__test_assets__/getStripeCredentials");
const getStripe_1 = require("../auth/getStripe");
const setCustomer_1 = require("../customer/setCustomer");
const genInvoiceDraft_1 = require("./genInvoiceDraft");
const log = console;
describe('genInvoiceDraft', () => {
(0, test_fns_1.given)('a customer', () => {
let customerFound;
beforeAll(async () => {
customerFound = await (0, setCustomer_1.setCustomer)({
finsert: {
email: 'svc-protools@ahbode.dev',
name: 'svc-protools.test',
description: 'test',
metadata: null,
phone: null,
},
}, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log });
});
(0, test_fns_1.when)('we attempt to generate a new invoice for them', () => {
const exid = (0, uuid_fns_1.getUuid)();
let invoiceId;
(0, test_fns_1.then)('we should succeed', async () => {
const invoice = await (0, genInvoiceDraft_1.genInvoiceDraft)({
invoice: {
customerRef: customerFound,
exid,
config: {
autoAdvance: false,
collectionMethod: 'charge_automatically',
},
description: null,
dueDate: null,
metadata: null,
},
}, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log });
console.log(invoice);
expect(invoice.status).toEqual('draft');
invoiceId = invoice.id;
});
(0, test_fns_1.then)('it should be idempotent', async () => {
const invoice = await (0, genInvoiceDraft_1.genInvoiceDraft)({
invoice: {
customerRef: customerFound,
exid,
config: {
autoAdvance: false,
collectionMethod: 'charge_automatically',
},
description: null,
metadata: null,
dueDate: null,
},
}, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log });
console.log(invoice);
expect(invoice.status).toEqual('draft');
expect(invoice.id).toEqual(invoiceId); // same invoice, not a new one
});
});
});
(0, test_fns_1.given)('a customer', () => {
let customerFound;
beforeAll(async () => {
customerFound = await (0, setCustomer_1.setCustomer)({
finsert: {
email: 'svc-protools@ahbode.dev',
name: 'svc-protools.test',
description: 'test',
metadata: null,
phone: null,
},
}, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log });
});
(0, test_fns_1.when)('we attempt to generate a new invoice for them with a due date', () => {
const exid = (0, uuid_fns_1.getUuid)();
let invoiceId;
(0, test_fns_1.then)('we should succeed', async () => {
const invoice = await (0, genInvoiceDraft_1.genInvoiceDraft)({
invoice: {
customerRef: customerFound,
exid,
config: {
autoAdvance: false,
collectionMethod: 'send_invoice',
},
description: null,
dueDate: (0, uni_time_1.addDuration)((0, uni_time_1.asUniDate)(new Date()), { days: 7 }),
metadata: null,
},
}, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log });
expect(invoice.status).toEqual('draft');
expect(invoice.dueDate).not.toEqual(null);
});
});
});
(0, test_fns_1.when)('we attempt to generate an invoice which was previously issued', () => {
test_fns_1.then.todo('it should throw a bad request error');
});
});
//# sourceMappingURL=genInvoiceDraft.integration.test.js.map