Skip to content

Commit

Permalink
795th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jan 20, 2020
1 parent f5ee001 commit a4ba4d4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 70 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -67,6 +67,7 @@
"@storybook/addons": "5.2.8",
"@storybook/vue": "5.2.8",
"@vue/test-utils": "1.0.0-beta.30",
"axios-mock-adapter": "1.17.0",
"babel-eslint": "8.2.6",
"babel-jest": "24.8.0",
"babel-loader": "8.0.5",
Expand Down
8 changes: 0 additions & 8 deletions src/shell/crud-operations/rest/__mocks__/axios.js

This file was deleted.

97 changes: 35 additions & 62 deletions src/shell/crud-operations/rest/__tests__/actions.spec.js
@@ -1,7 +1,10 @@
import { INITIAL } from '../constants';
import axios from 'axios';
import AxiosMockAdapter from 'axios-mock-adapter';

import { API_LIST, INITIAL } from '../constants';
import actions from '../actions';

jest.mock('axios');
const mockAxios = new AxiosMockAdapter(axios);

describe('actions', () => {
it('should handle success', () => {
Expand All @@ -26,30 +29,22 @@ describe('actions', () => {
actions.failure({ commit }, error);
});

it('should handle addItem (success)', (done) => {
const dispatch = (type) => {
expect(type).toBe('searchItem');
done();
};
it('should handle addItem (success)', async () => {
mockAxios.onPost(API_LIST).reply(200, { message: 'Data saved.' });

const dispatch = (type) => { expect(type).toBe('searchItem'); };
const state = { ...INITIAL };

const payload = 'qaz123';

actions.addItem({ dispatch, state }, payload);
await actions.addItem({ dispatch, state }, payload);
});

it('should handle addItem (failure)', (done) => {
const dispatch = (type) => {
expect(type).toBe('failure');
done();
};

it('should handle addItem (failure)', async () => {
const dispatch = (type) => { expect(type).toBe('failure'); };
const state = { ...INITIAL };

const payload = new Error('Error!');

actions.addItem({ dispatch, state }, payload);
await actions.addItem({ dispatch, state }, payload);
});

it('should handle addItem (undefined)', async () => {
Expand All @@ -58,86 +53,64 @@ describe('actions', () => {
const payload = '';

const result = await actions.addItem({ dispatch, state }, payload);

expect(result).toBeUndefined();
});

it('should handle searchItem (success)', (done) => {
it('should handle searchItem (success)', async () => {
mockAxios.onGet(API_LIST).reply(200, { data: [{ id: 'vn3RecDbwMQTjttnluZW', text: 'qaz123' }] });

const dispatch = (type, payload) => {
expect(type).toBe('success');
expect(payload).toEqual([{ id: 'vn3RecDbwMQTjttnluZW', text: 'qaz123' }]);
done();
expect(payload).toEqual({ data: [{ id: 'vn3RecDbwMQTjttnluZW', text: 'qaz123' }] });
};

const state = { ...INITIAL };

const payload = '';

actions.searchItem({ dispatch, state }, payload);
await actions.searchItem({ dispatch, state }, payload);
});

it('should handle searchItem (failure)', (done) => {
const dispatch = (type) => {
expect(type).toBe('failure');
done();
};

it('should handle searchItem (failure)', async () => {
const dispatch = (type) => { expect(type).toBe('failure'); };
const state = { ...INITIAL };

const payload = '';

actions.searchItem({ dispatch, state }, payload);
await actions.searchItem({ dispatch, state }, payload);
});

it('should handle editItem (success)', (done) => {
const dispatch = (type) => {
expect(type).toBe('searchItem');
done();
};
it('should handle editItem (success)', async () => {
mockAxios.onPut(`${API_LIST}/vn3RecDbwMQTjttnluZW`).reply(200, { message: 'Data updated.' });

const dispatch = (type) => { expect(type).toBe('searchItem'); };
const state = { ...INITIAL };
const payload = { id: 'vn3RecDbwMQTjttnluZW', text: 'zxc123' };

const payload = { id: 'vn3RecDbwMQTjttnluZW', text: 'qaz123' };

actions.editItem({ dispatch, state }, payload);
await actions.editItem({ dispatch, state }, payload);
});

it('should handle editItem (failure)', (done) => {
const dispatch = (type) => {
expect(type).toBe('failure');
done();
};

it('should handle editItem (failure)', async () => {
const dispatch = (type) => { expect(type).toBe('failure'); };
const state = { ...INITIAL };

const payload = { id: 'vn3RecDbwMQTjttnluZW', text: new Error('Error!') };

actions.editItem({ dispatch, state }, payload);
await actions.editItem({ dispatch, state }, payload);
});

it('should handle deleteItem (success)', (done) => {
const dispatch = (type) => {
expect(type).toBe('searchItem');
done();
};
it('should handle deleteItem (success)', async () => {
mockAxios.onDelete(`${API_LIST}/vn3RecDbwMQTjttnluZW`).reply(200, { message: 'Data deleted.' });

const dispatch = (type) => { expect(type).toBe('searchItem'); };
const state = { ...INITIAL };

const payload = 'vn3RecDbwMQTjttnluZW';

actions.deleteItem({ dispatch, state }, payload);
await actions.deleteItem({ dispatch, state }, payload);
});

it('should handle deleteItem (failure)', (done) => {
const dispatch = (type) => {
expect(type).toBe('failure');
done();
};

it('should handle deleteItem (failure)', async () => {
const dispatch = (type) => { expect(type).toBe('failure'); };
const state = { ...INITIAL };

const payload = null;

actions.deleteItem({ dispatch, state }, payload);
await actions.deleteItem({ dispatch, state }, payload);
});
});
7 changes: 7 additions & 0 deletions yarn.lock
Expand Up @@ -2598,6 +2598,13 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.0.tgz#24390e6ad61386b0a747265754d2a17219de862c"
integrity sha512-Uvq6hVe90D0B2WEnUqtdgY1bATGz3mw33nH9Y+dmA+w5DHvUmBgkr5rM/KCHpCsiFNRUfokW/szpPPgMK2hm4A==

axios-mock-adapter@1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.17.0.tgz#0dbee43c606d4aaba5a43d88d96d6661a7cc3c04"
integrity sha512-q3efmwJUOO4g+wsLNSk9Ps1UlJoF3fQ3FSEe4uEEhkRtu7SoiAVPj8R3Hc/WP55MBTVFzaDP9QkdJhdVhP8A1Q==
dependencies:
deep-equal "^1.0.1"

axios@0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
Expand Down

0 comments on commit a4ba4d4

Please sign in to comment.