Created
March 20, 2017 20:09
-
-
Save thejohnnybot/d017b250e9c6c35ed5ca25a7014850e0 to your computer and use it in GitHub Desktop.
example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { extendObservable } from 'mobx'; | |
| import { setDefaultModelSchema, list, object, primitive } from 'serializr'; | |
| import { defaults } from 'lodash'; | |
| import Address from './Address'; | |
| import Customer from './Customer'; | |
| import Order from './Order'; | |
| class Checkout { | |
| constructor(obj) { | |
| const checkout = defaults({ | |
| id: '', | |
| abandoned_checkout_url: '', | |
| billing_address: {}, | |
| buyer_accepts_marketing: false, | |
| cart_token: '', | |
| closed_at: '', | |
| completed_at: '', | |
| created_at: '', | |
| currency: 'USD', | |
| customer: {}, | |
| discount_codes: [], | |
| email: '', | |
| gateway: '', | |
| landing_site: '', | |
| line_items: [], | |
| name: '', | |
| note_attributes: [], | |
| note: '', | |
| referring_site: '', | |
| shipping_address: {}, | |
| shipping_lines: [], | |
| source_identifier: '', | |
| source_name: '', | |
| source_url: '', | |
| source: '', | |
| subtotal_price: 0, | |
| tax_lines: [], | |
| taxes_included: false, | |
| token: '', | |
| total_discounts: 0, | |
| total_line_items_price: 0, | |
| total_price: 0, | |
| total_tax: 0, | |
| total_weight: 0, | |
| updated_at: '', | |
| }, obj); | |
| extendObservable(this, checkout); | |
| } | |
| } | |
| const checkoutSchema = { | |
| props: { | |
| id: primitive(), | |
| abandoned_checkout_url: primitive(), | |
| billing_address: object(Address), | |
| buyer_accepts_marketing: primitive(), | |
| cart_token: primitive(), | |
| closed_at: primitive(), | |
| completed_at: primitive(), | |
| created_at: primitive(), | |
| currency: primitive(), | |
| customer: object(Customer), | |
| discount_codes: list(), | |
| email: primitive(), | |
| gateway: primitive(), | |
| landing_site: primitive(), | |
| line_items: list(object(Order)), | |
| name: primitive(), | |
| note_attributes: list(), | |
| note: primitive(), | |
| referring_site: primitive(), | |
| shipping_address: object(Address), | |
| shipping_lines: list(), | |
| source_identifier: primitive(), | |
| source_name: primitive(), | |
| source_url: primitive(), | |
| source: primitive(), | |
| subtotal_price: primitive(), | |
| tax_lines: list(), | |
| taxes_included: primitive(), | |
| token: primitive(), | |
| total_discounts: primitive(), | |
| total_line_items_price: primitive(), | |
| total_price: primitive(), | |
| total_tax: primitive(), | |
| total_weight: primitive(), | |
| updated_at: primitive(), | |
| } | |
| }; | |
| setDefaultModelSchema(Checkout, checkoutSchema); | |
| export default Checkout; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Checkout from './Checkout'; | |
| import checkoutMock from '../utils/checkoutMock'; | |
| import { deserialize } from 'serializr'; | |
| it('constructs a new object', () => { | |
| const data = checkoutMock['checkouts'][0]; | |
| const checkout = deserialize(Checkout, data); | |
| expect(checkout.id).toBe(26371164); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Test suite failed to run | |
| [serializr] Illegal State | |
| at invariant (node_modules/serializr/serializr.js:26:23) | |
| at setDefaultModelSchema (node_modules/serializr/serializr.js:310:13) | |
| at Object.<anonymous> (src/store/Checkout.js:91:64) | |
| at Object.<anonymous> (src/store/Checkout.test.js:1:171) | |
| at process._tickCallback (internal/process/next_tick.js:103:7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment