all files / src/ generic-mock.js

100% Statements 12/12
100% Branches 2/2
100% Functions 5/5
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                  
const Mock = {
    store: {},
    setEntry(entryID, id, original) {
        if (!this.store[entryID]) {
            this.store[entryID] = {}
        }
        this.store[entryID][id] = { original, fake: original }
    },
    getEntry(entryID) {
        const entry = this.store[entryID]
        return {
            get: (id) => { this.getByID(entry, id) },
            set: (id, target) => { this.setMock(entry, id, target) },
            reset: (id) => { this.resetMock(entry, id) }
        }
    },
    getByID(mocks, id) {
        return mocks[id].fake
    },
    setMock(mocks, id, target) {
        mocks[id].fake = target
    },
    resetMock(mocks, id) {
        mocks[id].fake = mocks[id].original
    }
}
 
export default Mock