shelving
Version:
Toolkit for using data in JavaScript.
50 lines (49 loc) • 2.24 kB
JavaScript
import { MemoryDBProvider } from "./MemoryDBProvider.js";
/** Provider that logs database operations for testing purposes. */
export class MockDBProvider extends MemoryDBProvider {
calls = [];
async getItem(collection, id) {
const result = await super.getItem(collection, id);
this.calls.push({ type: "getItem", collection: collection.name, id, result });
return result;
}
async addItem(collection, data) {
const result = await super.addItem(collection, data);
this.calls.push({ type: "addItem", collection: collection.name, data, result });
return result;
}
async setItem(collection, id, data) {
await super.setItem(collection, id, data);
this.calls.push({ type: "setItem", collection: collection.name, id, data });
}
async updateItem(collection, id, updates) {
await super.updateItem(collection, id, updates);
this.calls.push({ type: "updateItem", collection: collection.name, id, updates });
}
async deleteItem(collection, id) {
await super.deleteItem(collection, id);
this.calls.push({ type: "deleteItem", collection: collection.name, id });
}
async countQuery(collection, query) {
const result = await super.countQuery(collection, query);
this.calls.push({ type: "countQuery", collection: collection.name, query, result });
return result;
}
async getQuery(collection, query) {
const result = await super.getQuery(collection, query);
this.calls.push({ type: "getQuery", collection: collection.name, query, result });
return result;
}
async setQuery(collection, query, data) {
await super.setQuery(collection, query, data);
this.calls.push({ type: "setQuery", collection: collection.name, query, data });
}
async updateQuery(collection, query, updates) {
await super.updateQuery(collection, query, updates);
this.calls.push({ type: "updateQuery", collection: collection.name, query, updates });
}
async deleteQuery(collection, query) {
await super.deleteQuery(collection, query);
this.calls.push({ type: "deleteQuery", collection: collection.name, query });
}
}