mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Client: remove unnecessary API calls + members fixes (#12179)
* wip * refactor world state * allow resource to be reloaded when the server is updated * fix #9242 * fix event listeners * remove un-needed code * add tests for asyncResourceFactory reloadOnAppVersionChange * fix double cron notifications and party members showing up in the header after a party invitation is accepted * remove console.log * do not send vm info to loggly due to circular dependency + fix typo * fix #12181 * do not load invites multiple times in members modal * add hover to challenge member count * groups: load members only on demand * minor ui fixes * choose class: fix vue duplicate key warning * minor ui fixes * challanges: load members on demand * add loading spinner * change loading mechanism * fix loading gryphon issues * reduce code duplication
This commit is contained in:
@@ -123,6 +123,56 @@ describe('async resource', () => {
|
||||
expect(axios.get).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
describe('reloadOnAppVersionChange', async () => {
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
store = generateStore();
|
||||
store.state.worldState.loadingStatus = 'LOADED';
|
||||
store.state.serverAppVersion = 1;
|
||||
store.state.worldState.appVersionOnLoad = 1;
|
||||
});
|
||||
|
||||
it('load the resource if it is loaded but the appVersion has changed', async () => {
|
||||
store.state.serverAppVersion = 2;
|
||||
sandbox.stub(axios, 'get').withArgs('/api/v4/world-state').returns(Promise.resolve({
|
||||
data: { data: { _id: 1 } },
|
||||
}));
|
||||
|
||||
const resource = await loadAsyncResource({
|
||||
store,
|
||||
path: 'worldState',
|
||||
url: '/api/v4/world-state',
|
||||
reloadOnAppVersionChange: true,
|
||||
deserialize (response) {
|
||||
return response.data.data;
|
||||
},
|
||||
});
|
||||
|
||||
expect(resource).to.equal(store.state.worldState);
|
||||
expect(resource.loadingStatus).to.equal('LOADED');
|
||||
expect(resource.data._id).to.equal(1);
|
||||
expect(axios.get).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('does not load the resource if it is loaded but the appVersion has changed', async () => {
|
||||
sandbox.stub(axios, 'get').returns(Promise.resolve({ data: { data: { _id: 1 } } }));
|
||||
|
||||
const resource = await loadAsyncResource({
|
||||
store,
|
||||
path: 'worldState',
|
||||
url: '/api/v4/world-state',
|
||||
reloadOnAppVersionChange: true,
|
||||
deserialize (response) {
|
||||
return response.data.data;
|
||||
},
|
||||
});
|
||||
|
||||
expect(resource).to.equal(store.state.worldState);
|
||||
expect(axios.get).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
|
||||
it('does not send multiple requests if the resource is being loaded', async () => {
|
||||
const store = generateStore();
|
||||
store.state.user.loadingStatus = 'LOADING';
|
||||
|
||||
Reference in New Issue
Block a user