| 223 | }, |
| 224 | |
| 225 | expectsql(query, assertions) { |
| 226 | const rawExpectationMap = |
| 227 | 'query' in assertions ? assertions.query : assertions; |
| 228 | const expectations = Object.create(null); |
| 229 | |
| 230 | for (const [key, value] of Object.entries(rawExpectationMap)) { |
| 231 | const acceptedDialects = key.split(' '); |
| 232 | |
| 233 | for (const dialect of acceptedDialects) { |
| 234 | if (dialect === 'default' && acceptedDialects.length > 1) { |
| 235 | throw new Error( |
| 236 | 'The \'default\' expectation cannot be combined with other dialects.' |
| 237 | ); |
| 238 | } |
| 239 | |
| 240 | if (expectations[dialect] !== undefined) { |
| 241 | throw new Error( |
| 242 | `The expectation for ${dialect} was already defined.` |
| 243 | ); |
| 244 | } |
| 245 | |
| 246 | expectations[dialect] = value; |
| 247 | } |
| 248 | } |
| 249 | let expectation = expectations[Support.sequelize.dialect.name]; |
| 250 | const dialect = Support.sequelize.dialect; |
| 251 | |
| 252 | if (!expectation) { |
| 253 | if (expectations['default'] !== undefined) { |
| 254 | expectation = expectations['default']; |
| 255 | if (typeof expectation === 'string') { |
| 256 | // replace [...] with the proper quote character for the dialect |
| 257 | // except for ARRAY[...] |
| 258 | expectation = expectation.replace(/(?<!ARRAY)\[([^\]]+)]/g, `${dialect.TICK_CHAR_LEFT}$1${dialect.TICK_CHAR_RIGHT}`); |
| 259 | } |
| 260 | } else { |
| 261 | throw new Error(`Undefined expectation for "${Support.sequelize.dialect.name}"!`); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | if (query instanceof Error) { |
| 266 | expect(query.message).to.equal(expectation.message); |
| 267 | } else { |
| 268 | expect(Support.minifySql(query.query || query)).to.equal(Support.minifySql(expectation)); |
| 269 | } |
| 270 | |
| 271 | if (assertions.bind) { |
| 272 | const bind = assertions.bind[Support.sequelize.dialect.name] || assertions.bind['default'] || assertions.bind; |
| 273 | expect(query.bind).to.deep.equal(bind); |
| 274 | } |
| 275 | }, |
| 276 | |
| 277 | rand() { |
| 278 | return Math.floor(Math.random() * 10e5); |