|
| 1 | +// eslint-disable-next-line max-classes-per-file |
| 2 | +import { |
| 3 | + BeforeCreateMany, |
| 4 | + BeforeCreateOne, |
| 5 | + BeforeUpdateOne, |
| 6 | + BeforeUpdateMany, |
| 7 | + BeforeDeleteOne, |
| 8 | + BeforeDeleteMany, |
| 9 | + BeforeQueryMany, |
| 10 | + BeforeFindOne, |
| 11 | +} from '../../src'; |
| 12 | +import { |
| 13 | + getCreateManyHook, |
| 14 | + getCreateOneHook, |
| 15 | + getUpdateOneHook, |
| 16 | + getUpdateManyHook, |
| 17 | + getDeleteOneHook, |
| 18 | + getDeleteManyHook, |
| 19 | + getQueryManyHook, |
| 20 | + getFindOneHook, |
| 21 | +} from '../../src/decorators'; |
| 22 | + |
| 23 | +describe('hook decorators', () => { |
| 24 | + describe('@BeforeCreateOne', () => { |
| 25 | + it('should store the hook', () => { |
| 26 | + const hookFn = jest.fn(); |
| 27 | + @BeforeCreateOne(hookFn) |
| 28 | + class Test {} |
| 29 | + |
| 30 | + expect(getCreateOneHook(Test)).toBe(hookFn); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return a hook from the base class', () => { |
| 34 | + const hookFn = jest.fn(); |
| 35 | + @BeforeCreateOne(hookFn) |
| 36 | + class Base {} |
| 37 | + |
| 38 | + class Test extends Base {} |
| 39 | + |
| 40 | + expect(getCreateOneHook(Test)).toBe(hookFn); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 44 | + const baseHookFn = jest.fn(); |
| 45 | + @BeforeCreateOne(baseHookFn) |
| 46 | + class Base {} |
| 47 | + |
| 48 | + const childHookFn = jest.fn(); |
| 49 | + @BeforeCreateOne(childHookFn) |
| 50 | + class Test extends Base {} |
| 51 | + |
| 52 | + expect(getCreateOneHook(Test)).toBe(childHookFn); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('@BeforeCreateMany', () => { |
| 57 | + it('should store the hook', () => { |
| 58 | + const hookFn = jest.fn(); |
| 59 | + @BeforeCreateMany(hookFn) |
| 60 | + class Test {} |
| 61 | + |
| 62 | + expect(getCreateManyHook(Test)).toBe(hookFn); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should return a hook from the base class', () => { |
| 66 | + const hookFn = jest.fn(); |
| 67 | + @BeforeCreateMany(hookFn) |
| 68 | + class Base {} |
| 69 | + |
| 70 | + class Test extends Base {} |
| 71 | + |
| 72 | + expect(getCreateManyHook(Test)).toBe(hookFn); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 76 | + const baseHookFn = jest.fn(); |
| 77 | + @BeforeCreateMany(baseHookFn) |
| 78 | + class Base {} |
| 79 | + |
| 80 | + const childHookFn = jest.fn(); |
| 81 | + @BeforeCreateMany(childHookFn) |
| 82 | + class Test extends Base {} |
| 83 | + |
| 84 | + expect(getCreateManyHook(Test)).toBe(childHookFn); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + describe('@BeforeUpdateOne', () => { |
| 89 | + it('should store the hook', () => { |
| 90 | + const hookFn = jest.fn(); |
| 91 | + @BeforeUpdateOne(hookFn) |
| 92 | + class Test {} |
| 93 | + |
| 94 | + expect(getUpdateOneHook(Test)).toBe(hookFn); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should return a hook from the base class', () => { |
| 98 | + const hookFn = jest.fn(); |
| 99 | + @BeforeUpdateOne(hookFn) |
| 100 | + class Base {} |
| 101 | + |
| 102 | + class Test extends Base {} |
| 103 | + |
| 104 | + expect(getUpdateOneHook(Test)).toBe(hookFn); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 108 | + const baseHookFn = jest.fn(); |
| 109 | + @BeforeUpdateOne(baseHookFn) |
| 110 | + class Base {} |
| 111 | + |
| 112 | + const childHookFn = jest.fn(); |
| 113 | + @BeforeUpdateOne(childHookFn) |
| 114 | + class Test extends Base {} |
| 115 | + |
| 116 | + expect(getUpdateOneHook(Test)).toBe(childHookFn); |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + describe('@BeforeUpdateMany', () => { |
| 121 | + it('should store the hook', () => { |
| 122 | + const hookFn = jest.fn(); |
| 123 | + @BeforeUpdateMany(hookFn) |
| 124 | + class Test {} |
| 125 | + |
| 126 | + expect(getUpdateManyHook(Test)).toBe(hookFn); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should return a hook from the base class', () => { |
| 130 | + const hookFn = jest.fn(); |
| 131 | + @BeforeUpdateMany(hookFn) |
| 132 | + class Base {} |
| 133 | + |
| 134 | + class Test extends Base {} |
| 135 | + |
| 136 | + expect(getUpdateManyHook(Test)).toBe(hookFn); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 140 | + const baseHookFn = jest.fn(); |
| 141 | + @BeforeUpdateMany(baseHookFn) |
| 142 | + class Base {} |
| 143 | + |
| 144 | + const childHookFn = jest.fn(); |
| 145 | + @BeforeUpdateMany(childHookFn) |
| 146 | + class Test extends Base {} |
| 147 | + |
| 148 | + expect(getUpdateManyHook(Test)).toBe(childHookFn); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + describe('@BeforeDeleteOne', () => { |
| 153 | + it('should store the hook', () => { |
| 154 | + const hookFn = jest.fn(); |
| 155 | + @BeforeDeleteOne(hookFn) |
| 156 | + class Test {} |
| 157 | + |
| 158 | + expect(getDeleteOneHook(Test)).toBe(hookFn); |
| 159 | + }); |
| 160 | + |
| 161 | + it('should return a hook from the base class', () => { |
| 162 | + const hookFn = jest.fn(); |
| 163 | + @BeforeDeleteOne(hookFn) |
| 164 | + class Base {} |
| 165 | + |
| 166 | + class Test extends Base {} |
| 167 | + |
| 168 | + expect(getDeleteOneHook(Test)).toBe(hookFn); |
| 169 | + }); |
| 170 | + |
| 171 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 172 | + const baseHookFn = jest.fn(); |
| 173 | + @BeforeDeleteOne(baseHookFn) |
| 174 | + class Base {} |
| 175 | + |
| 176 | + const childHookFn = jest.fn(); |
| 177 | + @BeforeDeleteOne(childHookFn) |
| 178 | + class Test extends Base {} |
| 179 | + |
| 180 | + expect(getDeleteOneHook(Test)).toBe(childHookFn); |
| 181 | + }); |
| 182 | + }); |
| 183 | + |
| 184 | + describe('@BeforeDeleteMany', () => { |
| 185 | + it('should store the hook', () => { |
| 186 | + const hookFn = jest.fn(); |
| 187 | + @BeforeDeleteMany(hookFn) |
| 188 | + class Test {} |
| 189 | + |
| 190 | + expect(getDeleteManyHook(Test)).toBe(hookFn); |
| 191 | + }); |
| 192 | + |
| 193 | + it('should return a hook from the base class', () => { |
| 194 | + const hookFn = jest.fn(); |
| 195 | + @BeforeDeleteMany(hookFn) |
| 196 | + class Base {} |
| 197 | + |
| 198 | + class Test extends Base {} |
| 199 | + |
| 200 | + expect(getDeleteManyHook(Test)).toBe(hookFn); |
| 201 | + }); |
| 202 | + |
| 203 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 204 | + const baseHookFn = jest.fn(); |
| 205 | + @BeforeDeleteMany(baseHookFn) |
| 206 | + class Base {} |
| 207 | + |
| 208 | + const childHookFn = jest.fn(); |
| 209 | + @BeforeDeleteMany(childHookFn) |
| 210 | + class Test extends Base {} |
| 211 | + |
| 212 | + expect(getDeleteManyHook(Test)).toBe(childHookFn); |
| 213 | + }); |
| 214 | + }); |
| 215 | + |
| 216 | + describe('@BeforeQueryMany', () => { |
| 217 | + it('should store the hook', () => { |
| 218 | + const hookFn = jest.fn(); |
| 219 | + @BeforeQueryMany(hookFn) |
| 220 | + class Test {} |
| 221 | + |
| 222 | + expect(getQueryManyHook(Test)).toBe(hookFn); |
| 223 | + }); |
| 224 | + |
| 225 | + it('should return a hook from the base class', () => { |
| 226 | + const hookFn = jest.fn(); |
| 227 | + @BeforeQueryMany(hookFn) |
| 228 | + class Base {} |
| 229 | + |
| 230 | + class Test extends Base {} |
| 231 | + |
| 232 | + expect(getQueryManyHook(Test)).toBe(hookFn); |
| 233 | + }); |
| 234 | + |
| 235 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 236 | + const baseHookFn = jest.fn(); |
| 237 | + @BeforeQueryMany(baseHookFn) |
| 238 | + class Base {} |
| 239 | + |
| 240 | + const childHookFn = jest.fn(); |
| 241 | + @BeforeQueryMany(childHookFn) |
| 242 | + class Test extends Base {} |
| 243 | + |
| 244 | + expect(getQueryManyHook(Test)).toBe(childHookFn); |
| 245 | + }); |
| 246 | + }); |
| 247 | + |
| 248 | + describe('@BeforeFindOne', () => { |
| 249 | + it('should store the hook', () => { |
| 250 | + const hookFn = jest.fn(); |
| 251 | + @BeforeFindOne(hookFn) |
| 252 | + class Test {} |
| 253 | + |
| 254 | + expect(getFindOneHook(Test)).toBe(hookFn); |
| 255 | + }); |
| 256 | + |
| 257 | + it('should return a hook from the base class', () => { |
| 258 | + const hookFn = jest.fn(); |
| 259 | + @BeforeFindOne(hookFn) |
| 260 | + class Base {} |
| 261 | + |
| 262 | + class Test extends Base {} |
| 263 | + |
| 264 | + expect(getFindOneHook(Test)).toBe(hookFn); |
| 265 | + }); |
| 266 | + |
| 267 | + it('should return a hook from the child class if there is a hook on both the base and child', () => { |
| 268 | + const baseHookFn = jest.fn(); |
| 269 | + @BeforeFindOne(baseHookFn) |
| 270 | + class Base {} |
| 271 | + |
| 272 | + const childHookFn = jest.fn(); |
| 273 | + @BeforeFindOne(childHookFn) |
| 274 | + class Test extends Base {} |
| 275 | + |
| 276 | + expect(getFindOneHook(Test)).toBe(childHookFn); |
| 277 | + }); |
| 278 | + }); |
| 279 | +}); |
0 commit comments