Skip to content

Commit f2164dd

Browse files
more tests for hooks added to make coverage reporter happy
1 parent c606da2 commit f2164dd

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test/models/Hook.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { AfterSave, AfterUpdate, BeforeSave, BeforeUpdate } from "../../index";
88
import { BeforeCreate, BeforeValidate, Column, Model, Table } from "../../index";
99
import { BeforeFind, BeforeFindAfterExpandIncludeAll } from "../../index";
1010
import { BeforeBulkDelete, AfterBulkDelete, AfterDelete, BeforeDelete } from "../../index";
11+
import {AfterBulkSync} from '../../lib/annotations/hooks/AfterBulkSync';
12+
import {AfterConnect} from '../../lib/annotations/hooks/AfterConnect';
13+
import {AfterDefine} from '../../lib/annotations/hooks/AfterDefine';
14+
import {AfterInit} from '../../lib/annotations/hooks/AfterInit';
15+
import {BeforeBulkSync} from '../../lib/annotations/hooks/BeforeBulkSync';
16+
import {BeforeConnect} from '../../lib/annotations/hooks/BeforeConnect';
17+
import {BeforeDefine} from '../../lib/annotations/hooks/BeforeDefine';
18+
import {BeforeInit} from '../../lib/annotations/hooks/BeforeInit';
1119

1220
/**
1321
* Model used to test hook decorators. Defined hooks are mocked out for testing.
@@ -79,6 +87,30 @@ export class Hook extends Model<Hook> {
7987
@AfterBulkCreate
8088
static afterBulkCreateHook(instances: Hook[], options: any): void {}
8189

90+
@BeforeBulkSync
91+
static beforeBulkSyncHook(instances: Hook[], options: any): void {}
92+
93+
@AfterBulkSync
94+
static afterBulkSyncHook(instances: Hook[], options: any): void {}
95+
96+
@BeforeConnect
97+
static beforeConnectHook(instances: Hook[], options: any): void {}
98+
99+
@AfterConnect
100+
static afterConnectHook(instances: Hook[], options: any): void {}
101+
102+
@BeforeDefine
103+
static beforeDefineHook(instances: Hook[], options: any): void {}
104+
105+
@AfterDefine
106+
static afterDefineHook(instances: Hook[], options: any): void {}
107+
108+
@BeforeInit
109+
static beforeInitHook(instances: Hook[], options: any): void {}
110+
111+
@AfterInit
112+
static afterInitHook(instances: Hook[], options: any): void {}
113+
82114
@BeforeBulkDestroy
83115
static beforeBulkDestroyHook(options: any): void {}
84116

test/specs/hooks/hooks.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ describe('hook', () => {
8181
const afterFindHookStub = sinon.stub(Hook, 'afterFindHook');
8282
const beforeCountHookStub = sinon.stub(Hook, 'beforeCountHook');
8383

84+
const beforeBulkSyncHookStub = sinon.stub(Hook, 'beforeBulkSyncHook');
85+
const afterBulkSyncHookStub = sinon.stub(Hook, 'afterBulkSyncHook');
86+
const beforeConnectHookStub = sinon.stub(Hook, 'beforeConnectHook');
87+
const afterConnectHookStub = sinon.stub(Hook, 'afterConnectHook');
88+
const beforeDefineHookStub = sinon.stub(Hook, 'beforeDefineHook');
89+
const afterDefineHookStub = sinon.stub(Hook, 'afterDefineHook');
90+
const beforeInitHookStub = sinon.stub(Hook, 'beforeInitHook');
91+
const afterInitHookStub = sinon.stub(Hook, 'afterInitHook');
92+
8493
// these hooks are aliases for the equivalent “destroy” hooks
8594
const beforeDeleteHookStub = sinon.stub(Hook, 'beforeDeleteHook');
8695
const afterDeleteHookStub = sinon.stub(Hook, 'afterDeleteHook');
@@ -176,6 +185,15 @@ describe('hook', () => {
176185
expect(Hook['options'].hooks['afterFind']).to.include(afterFindHookStub);
177186
expect(Hook['options'].hooks['beforeCount']).to.include(beforeCountHookStub);
178187

188+
expect(Hook['options'].hooks['beforeBulkSync']).to.include(beforeBulkSyncHookStub);
189+
expect(Hook['options'].hooks['afterBulkSync']).to.include(afterBulkSyncHookStub);
190+
expect(Hook['options'].hooks['beforeConnect']).to.include(beforeConnectHookStub);
191+
expect(Hook['options'].hooks['afterConnect']).to.include(afterConnectHookStub);
192+
expect(Hook['options'].hooks['beforeDefine']).to.include(beforeDefineHookStub);
193+
expect(Hook['options'].hooks['afterDefine']).to.include(afterDefineHookStub);
194+
expect(Hook['options'].hooks['beforeInit']).to.include(beforeInitHookStub);
195+
expect(Hook['options'].hooks['afterInit']).to.include(afterInitHookStub);
196+
179197
expect(Hook['options'].hooks['beforeDestroy']).to.include(beforeDeleteHookStub);
180198
expect(Hook['options'].hooks['afterDestroy']).to.include(afterDeleteHookStub);
181199
expect(Hook['options'].hooks['beforeBulkDestroy']).to.include(beforeBulkDeleteHookStub);

0 commit comments

Comments
 (0)