Skip to content

Commit

Permalink
test: Improve upsert method test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaumgartl committed Nov 14, 2024
1 parent 0cedc13 commit 8409960
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/integration/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ describe('transaction', () => {
it('should accept data as an array of objects', async () => {
const table = 'trx_upsert_data_array';

await ctx.exec(`CREATE TABLE ${table} (id INT, col1 VARCHAR(10))`);
await ctx.transaction(
async (trx) =>
await trx.upsert(
table,
[
{ id: 1, col1: 'foo' },
{ id: 2, col1: 'bar' }
],
['col1']
)
);
await ctx.exec(`CREATE TABLE ${table} (id INT PRIMARY KEY, col1 VARCHAR(10))`);
await ctx.transaction(async (trx) => {
await trx.insert(table, { id: 1, col1: 'foobar' });
await trx.upsert(
table,
[
{ id: 1, col1: 'foo' },
{ id: 2, col1: 'bar' }
],
['col1']
);
});

const result = await ctx.query(`SELECT id, col1 FROM ${table}`);
const result = await ctx.query(`SELECT id, col1 FROM ${table} ORDER BY id`);
assert.equal(result.length, 2);
assert.deepEqual({ ...result[0] }, { id: 1, col1: 'foo' });
assert.deepEqual({ ...result[1] }, { id: 2, col1: 'bar' });
Expand Down

0 comments on commit 8409960

Please sign in to comment.