Skip to content

Commit 53a9f09

Browse files
Surbhi-sharma1samarpanB
authored andcommitted
test(sequelize): add test case for regex expression modification
add test case for regex expression modification 10312 Signed-off-by: Surbhi-sharma1 <[email protected]>
1 parent a7f4f24 commit 53a9f09

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

extensions/sequelize/src/__tests__/integration/repository.integration.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,61 @@ describe('Sequelize CRUD Repository (integration)', () => {
427427
expect(queryResult[0]).property('name').to.be.eql(bar.name);
428428
expect(queryResult[0]).property('email').to.be.eql(bar.email);
429429
});
430+
it('can execute command (select query with parenthesis) without parameters', async function () {
431+
await client.post('/users').send(getDummyUser({name: 'Foo'}));
432+
if (primaryDataSourceConfig.connector === 'sqlite3') {
433+
// Skip executing select query with bracket if datasource is sqlite
434+
// since it doesn't support it
435+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
436+
this.skip();
437+
}
438+
const queryResult = await userRepo.execute('(SELECT * from "user")');
439+
440+
expect(queryResult).to.have.length(1);
441+
expect(queryResult[0]).property('name').to.be.eql('Foo');
442+
});
443+
444+
it('can execute command (select query with parenthesis) using named parameters', async function () {
445+
await client.post('/users').send(getDummyUser({name: 'Foo'}));
446+
const bar = getDummyUser({name: 'Bar'});
447+
await client.post('/users').send(bar);
448+
if (primaryDataSourceConfig.connector === 'sqlite3') {
449+
// Skip executing select query with bracket if datasource is sqlite
450+
// since it doesn't support it
451+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
452+
this.skip();
453+
}
454+
const queryResult = await userRepo.execute(
455+
'(SELECT * from "user" where name = $name)',
456+
{
457+
name: 'Bar',
458+
},
459+
);
430460

461+
expect(queryResult).to.have.length(1);
462+
expect(queryResult[0]).property('name').to.be.eql(bar.name);
463+
expect(queryResult[0]).property('email').to.be.eql(bar.email);
464+
});
465+
it('can execute raw sql command (select query with parenthesis) using positional parameters', async function () {
466+
if (primaryDataSourceConfig.connector === 'sqlite3') {
467+
// Skip executing select query with bracket if datasource is sqlite
468+
// since it doesn't support it
469+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
470+
this.skip();
471+
}
472+
await client.post('/users').send(getDummyUser({name: 'Foo'}));
473+
const bar = getDummyUser({name: 'Bar'});
474+
await client.post('/users').send(bar);
475+
476+
const queryResult = await userRepo.execute(
477+
'(SELECT * from "user" where name = $1)',
478+
['Bar'],
479+
);
480+
481+
expect(queryResult).to.have.length(1);
482+
expect(queryResult[0]).property('name').to.be.eql(bar.name);
483+
expect(queryResult[0]).property('email').to.be.eql(bar.email);
484+
});
431485
it('can execute raw sql command (insert) using positional parameters', async () => {
432486
const user = getDummyUser({name: 'Foo', active: true});
433487
if (primaryDataSourceConfig.connector === 'sqlite3') {

0 commit comments

Comments
 (0)