UNPKG

declastruct-stripe-sdk

Version:

declarative control of stripe constructs, via declastruct

68 lines 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const domain_glossary_price_1 = require("domain-glossary-price"); const test_fns_1 = require("test-fns"); const uuid_fns_1 = require("uuid-fns"); const getStripeCredentials_1 = require("../../__test_assets__/getStripeCredentials"); const DeclaredStripeProduct_1 = require("../../domain/objects/DeclaredStripeProduct"); const getStripe_1 = require("../auth/getStripe"); const setProduct_1 = require("./setProduct"); const log = console; describe('setProduct', () => { (0, test_fns_1.given)('a new product we want to persist', () => { const product = new DeclaredStripeProduct_1.DeclaredStripeProduct({ id: `test_${(0, uuid_fns_1.getUuid)()}`, active: true, description: 'A super cool banjo!', name: 'Banjo 9000', price: new domain_glossary_price_1.Price({ amount: 19700, currency: 'USD', }), metadata: null, url: null, }); (0, test_fns_1.when)('we attempt to .finsert a new item', () => { (0, test_fns_1.then)('it should be able to create the product', async () => { const productCreated = await (0, setProduct_1.setProduct)({ finsert: product }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); expect(productCreated).toEqual(product); // should be exactly equal }); (0, test_fns_1.then)('it should NOT update the product on subsequent attempts', async () => { const newDescription = 'better description!'; const productCreated = await (0, setProduct_1.setProduct)({ finsert: { ...product, description: newDescription } }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); expect(productCreated.description).not.toEqual(newDescription); expect(productCreated).toEqual(product); // should still be exactly equal as original }); }); }); (0, test_fns_1.given)('a new product we want to persist', () => { const product = new DeclaredStripeProduct_1.DeclaredStripeProduct({ id: `test_${(0, uuid_fns_1.getUuid)()}`, active: true, name: 'OpenCNC 9000', description: 'A sweet open source cnc machine', price: new domain_glossary_price_1.Price({ amount: 19700, currency: 'USD', }), metadata: null, url: null, }); (0, test_fns_1.when)('we attempt to .upsert a new item', () => { (0, test_fns_1.then)('it should be able to create the product', async () => { const productCreated = await (0, setProduct_1.setProduct)({ upsert: product }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); expect(productCreated).toEqual(product); // should be exactly equal }); (0, test_fns_1.then)('it should update the product on subsequent attempts', async () => { const newDescription = 'better description!'; const productCreated = await (0, setProduct_1.setProduct)({ upsert: { ...product, description: newDescription } }, { stripe: await (0, getStripe_1.getStripe)((0, getStripeCredentials_1.getStripeCredentials)()), log }); expect(productCreated.description).toEqual(newDescription); expect(productCreated).toEqual({ ...product, description: newDescription, }); }); }); }); }); //# sourceMappingURL=setProduct.integration.test.js.map