From e59a7e473c04269e4feba6489dd3bb762e64a20e Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 13 Jul 2021 13:40:15 +0700 Subject: [PATCH] test: multiple values instead of single one --- test/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/index.ts b/test/index.ts index 1b9c771..b34640f 100644 --- a/test/index.ts +++ b/test/index.ts @@ -9,24 +9,27 @@ test('should be able to parse select query', () => { }); test('should be able to parse insert query', () => { - const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'pengangguran'})`; + const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`; assert.equal(query.sql, 'insert into users (name, age, profession) values ($1, $2, $3)'); - assert.equal(query.values, ['Jonas', 21, 'pengangguran']); + assert.equal(query.values, ['Jonas', 21, 'jobless']); }); test('should be able to parse to question marks', () => { - const query = sql`select * from 'users' where email = ${'example@mail.com'}`.formatQuestion(); - assert.equal(query, {sql: 'select * from \'users\' where email = ?', values: ['example@mail.com']}); + const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`.formatQuestion(); + assert.equal(query.sql, 'insert into users (name, age, profession) values (?, ?, ?)'); + assert.equal(query.values, ['Jonas', 21, 'jobless']); }); test('should be able to parse to colons', () => { - const query = sql`select * from 'users' where email = ${'example@mail.com'}`.formatColon(); - assert.equal(query, {sql: 'select * from \'users\' where email = :1', values: ['example@mail.com']}); + const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`.formatColon(); + assert.equal(query.sql, 'insert into users (name, age, profession) values (:1, :2, :3)'); + assert.equal(query.values, ['Jonas', 21, 'jobless']); }); test('should be able to parse to @p', () => { - const query = sql`select * from 'users' where email = ${'example@mail.com'}`.formatAtP(); - assert.equal(query, {sql: 'select * from \'users\' where email = @p1', values: ['example@mail.com']}); + const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`.formatAtP(); + assert.equal(query.sql, 'insert into users (name, age, profession) values (@p1, @p2, @p3)'); + assert.equal(query.values, ['Jonas', 21, 'jobless']); }); test.run();