MCPcopy
hub / github.com/sequelize/sequelize / testHooks

Function testHooks

test/integration/cls.test.js:141–175  ·  view source on GitHub ↗
({ method, hooks: hookNames, optionPos, execute, getModel })

Source from the content-addressed store, hash-verified

139 describe('Model Hook integration', () => {
140
141 function testHooks({ method, hooks: hookNames, optionPos, execute, getModel }) {
142 it(`passes the transaction to hooks {${hookNames.join(',')}} when calling ${method}`, async function() {
143 await this.sequelize.transaction(async transaction => {
144 const hooks = Object.create(null);
145
146 for (const hookName of hookNames) {
147 hooks[hookName] = sinon.spy();
148 }
149
150 const User = Reflect.apply(getModel, this, []);
151
152 for (const [hookName, spy] of Object.entries(hooks)) {
153 User[hookName](spy);
154 }
155
156 await Reflect.apply(execute, this, [User]);
157
158 const spyMatcher = [];
159 // ignore all arguments until we get to the option bag.
160 for (let i = 0; i < optionPos; i++) {
161 spyMatcher.push(sinon.match.any);
162 }
163
164 // find the transaction in the option bag
165 spyMatcher.push(sinon.match.has('transaction', transaction));
166
167 for (const [hookName, spy] of Object.entries(hooks)) {
168 expect(
169 spy,
170 `hook ${hookName} did not receive the transaction from CLS.`
171 ).to.have.been.calledWith(...spyMatcher);
172 }
173 });
174 });
175 }
176
177 testHooks({
178 method: 'Model.bulkCreate',

Callers 1

cls.test.jsFile · 0.85

Calls 3

transactionMethod · 0.80
createMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected