Skip to content

Commit

Permalink
test: ensure that dry models are not put (#22)
Browse files Browse the repository at this point in the history
* test: ensure that dry models are not put

* chore: fix empty functions
  • Loading branch information
acodeninja authored Sep 30, 2024
1 parent 3451c59 commit 0eb072c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/engine/Engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,38 @@ test('ImplementedEngine.search(MainModel, "test") when caching is on calls Imple

t.is(engine.getSearchIndexCompiled.getCalls().length, 1);
});

test('ImplementedEngine.put(partialModel) does not put dry models', async t => {
const models = new Models();
const model = models.createFullTestModel();

const partialModel = MainModel.fromData(model.toData());

class ImplementedEngine extends Engine {
static getById(id) {
return models.models[id];
}

static getSearchIndexCompiled = sinon.stub().callsFake((model) =>
Promise.resolve(JSON.parse(JSON.stringify(models.getSearchIndex(model)))),
);

static getSearchIndexRaw = sinon.stub().callsFake((model) =>
Promise.resolve(JSON.parse(JSON.stringify(models.getRawSearchIndex(model)))),
);

static putSearchIndexRaw = sinon.stub();

static putSearchIndexCompiled = sinon.stub();

static putIndex = sinon.stub();

static putModel = sinon.stub();
}

const engine = ImplementedEngine.configure({cache: {search: 5000}});

await engine.put(partialModel);

t.is(engine.putModel.getCalls().length, 1);
});

0 comments on commit 0eb072c

Please sign in to comment.