-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration.spec.ts
71 lines (59 loc) · 1.58 KB
/
integration.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Database, qb } from './fixtures/mysql'
import { connect } from '../index'
describe('Integration Test with Real MySQL Connection', () => {
const { db, close } = connect<Database>({ uri: 'mysql://root:root@localhost:3306/test' })
beforeAll(() => db.truncate('user'))
afterAll(() => close())
describe('Connection', () => {
test('ping', async() => {
await db.ping()
})
})
describe('Query', () => {
test('select', async() => {
const users = await db.query(qb
.selectFrom('user')
.selectAll()
.orderBy('id', 'desc'),
)
expect(users).toEqual([])
})
test('select with offset & limit', async() => {
const users = await db.query(qb
.selectFrom('user')
.selectAll()
.orderBy('id', 'desc')
.offset(0)
.limit(1),
)
expect(users).toEqual([])
})
})
describe('Execute', () => {
test('insert', async() => {
const { insertId } = await db.execute(qb
.insertInto('user')
.values({
name: 'kanziw',
email: 'kanziwoong@gmail.com',
}),
)
expect(insertId).toBe(1)
})
test('update', async() => {
const { affectedRows } = await db.execute(qb
.updateTable('user')
.set({ name: 'kanziw' })
.where('id', '=', '9999'),
)
expect(affectedRows).toBe(0)
})
test('delete', async() => {
const { affectedRows } = await db.execute(qb
.deleteFrom('user')
.where('id', '=', '9999'),
)
expect(affectedRows).toBe(0)
})
})
})