-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deleteFrom syntax and testing (#31)
- Loading branch information
Showing
5 changed files
with
66 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ScylloClient } from "../../lib"; | ||
|
||
type User = { | ||
username: string, | ||
uid: number | ||
} | ||
|
||
let DB: ScylloClient<{ 'users': User }>; | ||
|
||
beforeAll(async () => { | ||
DB = new ScylloClient({ | ||
client: { | ||
contactPoints: [ | ||
'localhost:9042' | ||
], | ||
localDataCenter: 'datacenter1', | ||
keyspace: 'scyllojestsuite' | ||
} | ||
}); | ||
await DB.awaitConnection(); | ||
}); | ||
|
||
it('Can delete a row from the database', async () => { | ||
await DB.insertInto('users', {uid: 432894398023546, username: 'Jest2'}) | ||
expect(await DB.deleteFrom('users', '*', {uid: 432894398023546})); | ||
}); | ||
|
||
it('Can delete a single field from the database', async () => { | ||
await DB.insertInto('users', {uid: 65098546897342, username: 'Jest3'}) | ||
expect(await DB.deleteFrom('users', ['username'], {uid: 65098546897342})); | ||
}); | ||
|
||
it('Expects deleting a non existent row to throw error', async () => { | ||
expect.assertions(1); | ||
try { | ||
await DB.deleteFrom('users', '*', {uid: 949575482946512, username: 'ThisUserShouldNotExist'}); | ||
} catch (e) { | ||
expect(e).toBeTruthy(); | ||
} | ||
}); | ||
|
||
afterAll(async () => { | ||
await DB.shutdown(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { selectOneFromRaw } from "../../lib"; | ||
import { deleteFromRaw } from "../../lib"; | ||
|
||
// fix | ||
it('Can insert a user into the database', async () => { | ||
expect(selectOneFromRaw<{'users': {uid: number, username: string}}, 'users'>('scyllo', 'users', '*', {uid: 1234567890, username: 'Jest'})).toEqual({query: 'SELECT * FROM scyllo.users WHERE uid=? AND username=? LIMIT 1', args: [1234567890, 'Jest']}); | ||
it('Can delete whole row', async () => { | ||
expect(deleteFromRaw<{'users': {uid: number, username: string}}, 'users', 'uid' | 'username', 'uid' | 'username'>('scyllo', 'users', '*', {uid: 1234567890, username: 'Jest'})).toEqual({query: 'DELETE FROM scyllo.users WHERE uid=? AND username=?', args: [1234567890, 'Jest']}); | ||
}); | ||
|
||
it('Can add extra args to query', async () => { | ||
expect(selectOneFromRaw<{'users': {uid: number, username: string}}, 'users'>('scyllo', 'users', '*', {uid: 1234567890, username: 'Jest'}, "ALLOW FILTERING")).toEqual({query: 'SELECT * FROM scyllo.users WHERE uid=? AND username=? LIMIT 1 ALLOW FILTERING', args: [1234567890, 'Jest']}); | ||
it('Can delete single field', async () => { | ||
expect(deleteFromRaw<{'users': {uid: number, username: string}}, 'users', 'uid' | 'username', 'uid' | 'username'>('scyllo', 'users', ['username'], {uid: 1234567890, username: 'Jest'})).toEqual({query: 'DELETE username FROM scyllo.users WHERE uid=? AND username=?', args: [1234567890, 'Jest']}); | ||
}); | ||
|
||
it('Can delete multiple fields', async () => { | ||
expect(deleteFromRaw<{'users': {uid: number, username: string}}, 'users', 'uid' | 'username', 'uid' | 'username'>('scyllo', 'users', ['username', 'uid'], {uid: 1234567890, username: 'Jest'})).toEqual({query: 'DELETE username,uid FROM scyllo.users WHERE uid=? AND username=?', args: [1234567890, 'Jest']}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters