mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-14 19:56:23 +00:00
54 lines
No EOL
1.6 KiB
JavaScript
54 lines
No EOL
1.6 KiB
JavaScript
import axios from 'axios';
|
|
import generateStore from '@/store';
|
|
|
|
describe('user actions', () => {
|
|
let store;
|
|
|
|
beforeEach(() => {
|
|
store = generateStore();
|
|
});
|
|
|
|
describe('fetch', () => {
|
|
it('loads the user', async () => {
|
|
expect(store.state.user.loadingStatus).to.equal('NOT_LOADED');
|
|
const user = {_id: 1};
|
|
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: user}}));
|
|
|
|
await store.dispatch('user:fetch');
|
|
|
|
expect(store.state.user.data).to.equal(user);
|
|
expect(store.state.user.loadingStatus).to.equal('LOADED');
|
|
});
|
|
|
|
it('does not reload user by default', async () => {
|
|
const originalUser = {_id: 1};
|
|
store.state.user = {
|
|
loadingStatus: 'LOADED',
|
|
data: originalUser,
|
|
};
|
|
|
|
const user = {_id: 2};
|
|
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: user}}));
|
|
|
|
await store.dispatch('user:fetch');
|
|
|
|
expect(store.state.user.data).to.equal(originalUser);
|
|
expect(store.state.user.loadingStatus).to.equal('LOADED');
|
|
});
|
|
|
|
it('can reload user if forceLoad is true', async () => {
|
|
store.state.user = {
|
|
loadingStatus: 'LOADED',
|
|
data: {_id: 1},
|
|
};
|
|
|
|
const user = {_id: 2};
|
|
sandbox.stub(axios, 'get').withArgs('/api/v4/user').returns(Promise.resolve({data: {data: user}}));
|
|
|
|
await store.dispatch('user:fetch', {forceLoad: true});
|
|
|
|
expect(store.state.user.data).to.equal(user);
|
|
expect(store.state.user.loadingStatus).to.equal('LOADED');
|
|
});
|
|
});
|
|
}); |