feat: cache custom attributes in IDB
This commit is contained in:
@@ -54,6 +54,17 @@ export const actions = {
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
revalidate: async ({ commit }, { newKey }) => {
|
||||
try {
|
||||
const isExistingKeyValid = await AttributeAPI.validateCacheKey(newKey);
|
||||
if (!isExistingKeyValid) {
|
||||
const response = await AttributeAPI.refetchAndCommit(newKey);
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE, response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
},
|
||||
create: async function createAttribute({ commit }, attributeObj) {
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import axios from 'axios';
|
||||
import { actions } from '../../attributes';
|
||||
import * as types from '../../../mutation-types';
|
||||
import AttributeAPI from '../../../../api/attributes';
|
||||
import attributesList from './fixtures';
|
||||
|
||||
const commit = vi.fn();
|
||||
global.axios = axios;
|
||||
vi.mock('axios');
|
||||
|
||||
// Clear the IDB-backed cache between tests so each case starts from a known
|
||||
// empty state and isn't affected by data persisted by a previous test.
|
||||
beforeEach(async () => {
|
||||
await AttributeAPI.dataManager.initDb();
|
||||
await AttributeAPI.dataManager.db.clear(AttributeAPI.cacheModelName);
|
||||
});
|
||||
|
||||
describe('#actions', () => {
|
||||
describe('#get', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
|
||||
Reference in New Issue
Block a user