Create util for apiLoadingStatus (#170)

* Create util for apiLoadingStatus

* Revert "Fix #52 rubocop metrics abc size in passwords controller (#119)"

This reverts commit 9c22da0ac6.
This commit is contained in:
Pranav Raj S 2019-10-22 13:28:45 +05:30 committed by GitHub
parent cd43b09574
commit e0d291c49e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 18 deletions

View file

@ -31,12 +31,11 @@ class PasswordsController < Devise::PasswordsController
def set_headers(user)
data = user.create_new_auth_token
headers_names = response.headers[DeviseTokenAuth.headers_names]
headers_names[:'access-token'] = data['access-token']
headers_names[:'token-type'] = 'Bearer'
headers_names[:'client'] = data['client']
headers_names[:'expiry'] = data['expiry']
headers_names[:'uid'] = data['uid']
response.headers[DeviseTokenAuth.headers_names[:"access-token"]] = data['access-token']
response.headers[DeviseTokenAuth.headers_names[:"token-type"]] = 'Bearer'
response.headers[DeviseTokenAuth.headers_names[:client]] = data['client']
response.headers[DeviseTokenAuth.headers_names[:expiry]] = data['expiry']
response.headers[DeviseTokenAuth.headers_names[:uid]] = data['uid']
end
def reset_password_and_confirmation(recoverable)

View file

@ -3,6 +3,7 @@
/* eslint no-shadow: 0 */
import * as types from '../mutation-types';
import Account from '../../api/account';
import { setLoadingStatus, getLoadingStatus } from '../utils/api';
const state = {
agents: [],
@ -16,9 +17,7 @@ const getters = {
getVerifiedAgents(_state) {
return _state.agents.filter(element => element.confirmed);
},
getAgentFetchStatus(_state) {
return _state.fetchAPIloadingStatus;
},
getAgentFetchStatus: getLoadingStatus,
};
const actions = {
@ -73,9 +72,7 @@ const actions = {
const mutations = {
// List
[types.default.SET_AGENT_FETCHING_STATUS](_state, flag) {
_state.fetchAPIloadingStatus = flag;
},
[types.default.SET_AGENT_FETCHING_STATUS]: setLoadingStatus,
// List
[types.default.SET_AGENTS](_state, response) {
_state.agents = response.data;

View file

@ -3,6 +3,7 @@
/* eslint no-shadow: 0 */
import * as types from '../mutation-types';
import CannedApi from '../../api/cannedResponse';
import { setLoadingStatus, getLoadingStatus } from '../utils/api';
const state = {
cannedResponse: [],
@ -13,9 +14,7 @@ const getters = {
getCannedResponses(_state) {
return _state.cannedResponse;
},
getCannedFetchStatus(_state) {
return _state.fetchAPIloadingStatus;
},
getCannedFetchStatus: getLoadingStatus,
};
const actions = {
@ -79,9 +78,7 @@ const actions = {
const mutations = {
// List
[types.default.SET_CANNED_FETCHING_STATUS](_state, flag) {
_state.fetchAPIloadingStatus = flag;
},
[types.default.SET_CANNED_FETCHING_STATUS]: setLoadingStatus,
// List
[types.default.SET_CANNED](_state, response) {
_state.cannedResponse = response.data;

View file

@ -0,0 +1,6 @@
/* eslint no-param-reassign: 0 */
export const getLoadingStatus = state => state.fetchAPIloadingStatus;
export const setLoadingStatus = (state, status) => {
state.fetchAPIloadingStatus = status;
};

View file

@ -0,0 +1,15 @@
import { getLoadingStatus, setLoadingStatus } from '../api';
describe('#getLoadingStatus', () => {
it('returns correct status', () => {
expect(getLoadingStatus({ fetchAPIloadingStatus: true })).toBe(true);
});
});
describe('#setLoadingStatus', () => {
it('set correct status', () => {
const state = { fetchAPIloadingStatus: true };
setLoadingStatus(state, false);
expect(state.fetchAPIloadingStatus).toBe(false);
});
});