UNPKG

declastruct-stripe-sdk

Version:

declarative control of stripe constructs, via declastruct

103 lines 5.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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("./setCustomer"); const log = console; describe('setCustomer', () => { (0, test_fns_1.given)('a .finsert', () => { (0, test_fns_1.when)('the customer does not exist yet', () => { const email = `svc-protools.test.${(0, uuid_fns_1.getUuid)()}@ahbode.dev`; // random uuid => new customer (0, test_fns_1.then)('we should create it', async () => { const customer = await (0, setCustomer_1.setCustomer)({ finsert: { email, name: 'svc-protools.test', description: 'test', metadata: null, phone: null, }, }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); console.log(customer); expect(customer.id).toContain('cus_'); }); }); (0, test_fns_1.when)('the customer already exists', () => { const email = `svc-protools.test.${(0, uuid_fns_1.getUuid)()}@ahbode.dev`; // random uuid => new customer let customerBefore; beforeAll(async () => { customerBefore = await (0, setCustomer_1.setCustomer)({ finsert: { email, 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.then)('it should not update the customers attributes', async () => { const customerAfter = await (0, setCustomer_1.setCustomer)({ finsert: { email, name: 'new name', description: 'test', metadata: null, phone: null, }, }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); expect(customerAfter.name).not.toEqual('new name'); expect(customerAfter.name).toEqual(customerBefore.name); }); }); }); (0, test_fns_1.given)('a .upsert', () => { (0, test_fns_1.when)('the customer does not exist yet', () => { const email = `svc-protools.test.${(0, uuid_fns_1.getUuid)()}@ahbode.dev`; // random uuid => new customer (0, test_fns_1.then)('we should create it', async () => { const customer = await (0, setCustomer_1.setCustomer)({ upsert: { email, name: 'svc-protools.test', description: 'test', metadata: null, phone: null, }, }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); console.log(customer); expect(customer.id).toContain('cus_'); }); }); (0, test_fns_1.when)('the customer already exists', () => { const email = `svc-protools.test.${(0, uuid_fns_1.getUuid)()}@ahbode.dev`; // random uuid => new customer let customerBefore; beforeAll(async () => { customerBefore = await (0, setCustomer_1.setCustomer)({ upsert: { email, 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.then)('it should update the customers attributes', async () => { const customerAfter = await (0, setCustomer_1.setCustomer)({ upsert: { email, name: 'new name', description: 'test', metadata: null, phone: null, }, }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); expect(customerAfter.name).toEqual('new name'); expect(customerAfter.name).not.toEqual(customerBefore.name); }); }); }); }); //# sourceMappingURL=setCustomer.integration.test.js.map