Sha256: c3aa078221765e1a0da287240daea9e25deaa4d5d6f8c40a5ceec5e9f55ffbf2
Contents?: true
Size: 1.84 KB
Versions: 3
Compression:
Stored size: 1.84 KB
Contents
import Sync from 'hippo/models/sync'; import Config from 'hippo/config'; import { Box } from '../test-models'; jest.unmock('hippo/models/sync'); describe('Network sync', () => { beforeEach(() => { Config.api_host = ''; }); it('makes a request', () => { fetch.mockResponseOnce(JSON.stringify({ access_token: '12345' })); Sync.perform('/foo') .then((json) => { expect(json).toEqual({ access_token: '12345' }); }); expect(fetch).toHaveBeenCalledWith( '/foo.json', { headers: { 'Content-Type': 'application/json' } }, ); }); it('makes request using options', () => { Sync.perform('/foo', { fields: ['test'] }); expect(fetch).lastCalledWith('/foo.json?f%5B%5D=test', expect.any(Object)); Sync.perform('/foo', { with: 'test' }); expect(fetch).lastCalledWith('/foo.json?w=test', expect.any(Object)); Sync.perform('/foo', { query: { bar: 'baz' } }); expect(fetch).lastCalledWith('/foo.json?q%5Bbar%5D=baz', expect.any(Object)); }); it('sets a models value', () => { fetch.mockResponseOnce(JSON.stringify({ data: { width: 12, height: 12, depth: 10 } })); const box = new Box({ width: 5 }); expect(box.width).toEqual(5); Sync.forModel(box, 'GET').then(() => expect(box.width).toEqual(12)); }); it('saves a model', () => { fetch.mockResponseOnce(JSON.stringify({ data: { width: 12, height: 12, depth: 10 } })); const box = new Box({ id: 11, width: 5 }); const body = JSON.stringify(box.syncData); Sync.forModel(box).then(() => expect(box.width).toEqual(12)); expect(fetch).lastCalledWith( '/api/test/box/11.json', { body, headers: { 'Content-Type': 'application/json' }, method: 'PUT' }); }); });
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hippo-fw-0.9.7 | spec/client/models/sync.spec.js |
hippo-fw-0.9.6 | spec/client/models/sync.spec.js |
hippo-fw-0.9.5 | spec/client/models/sync.spec.js |