不要怂,就是干,撸起袖子干!

Commit f1d08764 by Andy Edwards Committed by GitHub

refactor(query-interface): asyncify methods (#12126)

1 parent 39c35012
...@@ -128,34 +128,28 @@ if (dialect.match(/^postgres/)) { ...@@ -128,34 +128,28 @@ if (dialect.match(/^postgres/)) {
return Promise.all([ return Promise.all([
// requires functionName // requires functionName
expect(() => { expect(this.queryInterface.createFunction(null, [{ name: 'test' }], 'integer', 'plpgsql', body, options))
return this.queryInterface.createFunction(null, [{ name: 'test' }], 'integer', 'plpgsql', body, options); .to.be.rejectedWith(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
// requires Parameters array // requires Parameters array
expect(() => { expect(this.queryInterface.createFunction('create_job', null, 'integer', 'plpgsql', body, options))
return this.queryInterface.createFunction('create_job', null, 'integer', 'plpgsql', body, options); .to.be.rejectedWith(/function parameters array required/),
}).to.throw(/function parameters array required/),
// requires returnType // requires returnType
expect(() => { expect(this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], null, 'plpgsql', body, options))
return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], null, 'plpgsql', body, options); .to.be.rejectedWith(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
// requires type in parameter array // requires type in parameter array
expect(() => { expect(this.queryInterface.createFunction('create_job', [{ name: 'test' }], 'integer', 'plpgsql', body, options))
return this.queryInterface.createFunction('create_job', [{ name: 'test' }], 'integer', 'plpgsql', body, options); .to.be.rejectedWith(/function or trigger used with a parameter without any type/),
}).to.throw(/function or trigger used with a parameter without any type/),
// requires language // requires language
expect(() => { expect(this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', null, body, options))
return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', null, body, options); .to.be.rejectedWith(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/),
// requires body // requires body
expect(() => { expect(this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', 'plpgsql', null, options))
return this.queryInterface.createFunction('create_job', [{ type: 'varchar', name: 'test' }], 'varchar', 'plpgsql', null, options); .to.be.rejectedWith(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/)
}).to.throw(/createFunction missing some parameters. Did you pass functionName, returnType, language and body/)
]); ]);
}); });
...@@ -176,20 +170,14 @@ if (dialect.match(/^postgres/)) { ...@@ -176,20 +170,14 @@ if (dialect.match(/^postgres/)) {
it('produces an error when options.variables is missing expected parameters', function() { it('produces an error when options.variables is missing expected parameters', function() {
const body = 'return 1;'; const body = 'return 1;';
expect(() => { expect(this.queryInterface.createFunction('test_func', [], 'integer', 'plpgsql', body, [], { variables: 100 }))
const options = { variables: 100 }; .to.be.rejectedWith(/expandFunctionVariableList: function variables must be an array/);
return this.queryInterface.createFunction('test_func', [], 'integer', 'plpgsql', body, [], options);
}).to.throw(/expandFunctionVariableList: function variables must be an array/); expect(this.queryInterface.createFunction('test_func', [], 'integer', 'plpgsql', body, [], { variables: [{ name: 'myVar' }] }))
.to.be.rejectedWith(/function variable must have a name and type/);
expect(() => {
const options = { variables: [{ name: 'myVar' }] }; expect(this.queryInterface.createFunction('test_func', [], 'integer', 'plpgsql', body, [], { variables: [{ type: 'integer' }] }))
return this.queryInterface.createFunction('test_func', [], 'integer', 'plpgsql', body, [], options); .to.be.rejectedWith(/function variable must have a name and type/);
}).to.throw(/function variable must have a name and type/);
expect(() => {
const options = { variables: [{ type: 'integer' }] };
return this.queryInterface.createFunction('test_func', [], 'integer', 'plpgsql', body, [], options);
}).to.throw(/function variable must have a name and type/);
}); });
it('uses declared variables', function() { it('uses declared variables', function() {
...@@ -229,17 +217,14 @@ if (dialect.match(/^postgres/)) { ...@@ -229,17 +217,14 @@ if (dialect.match(/^postgres/)) {
it('produces an error when missing expected parameters', function() { it('produces an error when missing expected parameters', function() {
return Promise.all([ return Promise.all([
expect(() => { expect(this.queryInterface.dropFunction())
return this.queryInterface.dropFunction(); .to.be.rejectedWith(/.*requires functionName/),
}).to.throw(/.*requires functionName/),
expect(() => { expect(this.queryInterface.dropFunction('droptest'))
return this.queryInterface.dropFunction('droptest'); .to.be.rejectedWith(/.*function parameters array required/),
}).to.throw(/.*function parameters array required/),
expect(() => { expect(this.queryInterface.dropFunction('droptest', [{ name: 'test' }]))
return this.queryInterface.dropFunction('droptest', [{ name: 'test' }]); .to.be.rejectedWith(/.*function or trigger used with a parameter without any type/)
}).to.be.throw(/.*function or trigger used with a parameter without any type/)
]); ]);
}); });
}); });
......
...@@ -339,16 +339,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => { ...@@ -339,16 +339,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
} }
}); });
const testArgs = (...args) => { const testArgs = (...args) => expect(this.queryInterface.addColumn(...args))
expect(() => { .to.be.rejectedWith(Error, 'addColumn takes at least 3 arguments (table, attribute name, attribute definition)');
this.queryInterface.addColumn(...args);
throw new Error('Did not throw immediately...');
}).to.throw(Error, 'addColumn takes at least 3 arguments (table, attribute name, attribute definition)');
};
testArgs('users', 'level_id'); await testArgs('users', 'level_id');
testArgs(null, 'level_id'); await testArgs(null, 'level_id');
testArgs('users', null, {}); await testArgs('users', null, {});
}); });
it('should work with schemas', async function() { it('should work with schemas', async function() {
...@@ -539,14 +535,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => { ...@@ -539,14 +535,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
expect(constraints).to.not.include('check_user_roles'); expect(constraints).to.not.include('check_user_roles');
}); });
it('addconstraint missing type', function() { it('addconstraint missing type', async function() {
expect(() => { await expect(
this.queryInterface.addConstraint('users', ['roles'], { this.queryInterface.addConstraint('users', ['roles'], {
where: { roles: ['user', 'admin', 'guest', 'moderator'] }, where: { roles: ['user', 'admin', 'guest', 'moderator'] },
name: 'check_user_roles' name: 'check_user_roles'
}); })
throw new Error('Did not throw immediately...'); ).to.be.rejectedWith(Error, 'Constraint type must be specified through options.type');
}).to.throw(Error, 'Constraint type must be specified through options.type');
}); });
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!