-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_query_data.test.js
More file actions
77 lines (68 loc) · 1.57 KB
/
sql_query_data.test.js
File metadata and controls
77 lines (68 loc) · 1.57 KB
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
72
73
74
75
76
77
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
const { default: component } = await import('./sql_query_data.js')
const authors = [
{
"Name": "J.R.R. Tolkien",
"Born": 1892,
"Died": 1973,
},
{
"Name": "Jane Austen",
"Born": 1775,
"Died": 1817,
},
]
const books = [
{
"Title": "The Hobbit",
"Genre": "Fantasy",
"Author": "J.R.R. Tolkien",
},
{
"Title": "Pride and Prejudice",
"Genre": "Fiction",
"Author": "Jane Austen",
},
]
describe(component.name, () => {
it('should retrieve the specified row of data', async () => {
component.data_inputs = [books]
component.sql_query = 'SELECT Title FROM ? WHERE Genre = "Fiction"'
const response = await component.run({
steps: { trigger: {} },
$: {}
})
assert.equal(response.errors, undefined)
assert.deepEqual(
response.rows,
[
{ "Title": "Pride and Prejudice" }
]
)
})
it('should accept multiple inputs, such as for a JOIN', async () => {
component.data_inputs = [books, authors]
component.sql_query = `
SELECT
book.Title,
author.Name,
author.Born
FROM ? AS book
JOIN ? AS author
ON book.Author = author.Name
WHERE book.Genre = "Fantasy"
`
const response = await component.run({
steps: { trigger: {} },
$: {}
})
assert.equal(response.errors, undefined)
assert.deepEqual(
response.rows,
[
{ Born: 1892, Name: "J.R.R. Tolkien", Title: "The Hobbit" }
]
)
})
})