💚
This commit is contained in:
@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user