This commit is contained in:
Tom Moor
2017-11-20 00:09:46 -08:00
parent a8b6b51aa6
commit 1e75ce74e2

View File

@ -4,29 +4,24 @@ import CollectionsStore from './CollectionsStore';
jest.mock('utils/ApiClient', () => ({ jest.mock('utils/ApiClient', () => ({
client: { post: {} }, client: { post: {} },
})); }));
jest.mock('stores', () => ({ errors: {} })); jest.mock('stores', () => ({
errors: { add: jest.fn() }
}));
describe('CollectionsStore', () => { describe('CollectionsStore', () => {
let store; let store;
beforeEach(() => { beforeEach(() => {
const cache = { store = new CollectionsStore({});
getItem: jest.fn(() => Promise.resolve()),
setItem: jest.fn(() => {}),
};
store = new CollectionsStore({
teamId: 123,
cache,
});
}); });
describe('#fetch', () => { describe('#fetchAll', () => {
test('should load stores', async () => { test('should load stores', async () => {
store.client = { store.client = {
post: jest.fn(() => ({ post: jest.fn(() => ({
data: [ data: [
{ {
id: 123,
name: 'New collection', name: 'New collection',
}, },
], ],
@ -35,20 +30,15 @@ describe('CollectionsStore', () => {
await store.fetchAll(); await store.fetchAll();
expect(store.client.post).toHaveBeenCalledWith('/collections.list', { expect(store.client.post).toHaveBeenCalledWith('/collections.list');
id: 123, expect(store.data.size).toBe(1);
}); expect(store.data.values()[0].name).toBe('New collection');
expect(store.data.length).toBe(1);
expect(store.data[0].name).toBe('New collection');
}); });
test('should report errors', async () => { test('should report errors', async () => {
store.client = { store.client = {
post: jest.fn(() => Promise.reject), post: jest.fn(() => Promise.reject),
}; };
store.errors = {
add: jest.fn(),
};
await store.fetchAll(); await store.fetchAll();