-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_query_csv.test.js
More file actions
82 lines (68 loc) · 2.1 KB
/
Copy pathsql_query_csv.test.js
File metadata and controls
82 lines (68 loc) · 2.1 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
78
79
80
81
82
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
globalThis.defineComponent = (config) => config
const { default: component } = await import('./sql_query_csv.js')
const invalidCsvContent = `Title,Genre,Author
"Pride and Prejudice",Fiction,"J`
const booksCsvContent = `Title,Genre,Author
"The Hobbit",Fantasy,"J.R.R. Tolkien"
"Pride and Prejudice",Fiction,"Jane Austen"`
const authorsCsvContent = `Name,Born,Died
"J.R.R. Tolkien",1892,1973
"Jane Austen",1775,1817`
describe('SQL Query CSV', () => {
it('should retrieve the specified CSV row data', async () => {
component.csv_inputs = [booksCsvContent]
component.csv_inputs_have_header = [true]
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 handle CSV-parsing errors', async () => {
component.csv_inputs = [invalidCsvContent]
component.csv_inputs_have_header = [true]
component.sql_query = 'SELECT Title FROM ? WHERE Genre = "Fiction"'
const response = await component.run({
steps: { trigger: {} },
$: {}
})
assert.ok(
response.errors?.length > 0,
'Failed to return an error when given invalid CSV data'
)
})
it('should accept multiple CSVs, such as for a JOIN', async () => {
component.csv_inputs = [booksCsvContent, authorsCsvContent]
component.csv_inputs_have_header = [true, true]
component.sql_query = `
SELECT
books.Title,
authors.Name,
authors.Born
FROM ? AS books
JOIN ? AS authors
ON books.Author = authors.Name
WHERE books.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" }
]
)
})
})