-
Notifications
You must be signed in to change notification settings - Fork 11
/
testData.js
123 lines (123 loc) · 3.87 KB
/
testData.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module.exports.sqlParseTestData = [
{
sql: `SELECT topic(3) as deviceId, * FROM '$aws/things/sn:123/shadow/update' WHERE NOT state.reported.client.confirmed`,
payload: `{"state": {"reported": {"client": {"confirmed": false}}}}`,
expected: {
parsed: {
select: [{alias: 'deviceId', field: 'topic(3)'}, {field: '*'}],
topic: '$aws/things/sn:123/shadow/update',
whereClause: 'NOT state.reported.client.confirmed'
},
whereEvaluatesTo: true,
event: {
deviceId: 'sn:123',
state: {reported: {client: {confirmed: false}}}
}
}
},
{
sql: `SELECT state.reported.preferences.*, state.reported.activity as activityId FROM '$aws/things/+/shadow/update/accepted' WHERE state.reported.preferences.volume > 30`,
payload: `{"state": {"reported": {"preferences": {"volume": 31}, "activity": 1}}}`,
expected: {
parsed: {
select: [{field: 'state.reported.preferences.*'}, {field: 'state.reported.activity', alias: 'activityId'}],
topic: '$aws/things/+/shadow/update/accepted',
whereClause: 'state.reported.preferences.volume > 30'
},
whereEvaluatesTo: true,
event: {
volume: 31,
activityId: 1
}
}
},
{
sql: `SELECT state.desired.client FROM '$aws/things/+/shadow/update/accepted' WHERE state.desired.client = TRUE`,
payload: `{"state": {"desired": {"client": true}}}`,
expected: {
parsed: {
select: [{field: 'state.desired.client'}],
topic: '$aws/things/+/shadow/update/accepted',
whereClause: 'state.desired.client = TRUE'
},
whereEvaluatesTo: true,
event: {
client: true
}
}
},
{
sql: `SELECT *, topic(), topic(2), topic(3), topic(4) FROM '$aws/things/+/shadow/update' WHERE state.reported.mode = 'STAND_BY'`,
payload: `{"state": {"reported": {"mode": "STAND_BY"}}}`,
expected: {
parsed: {
select: [
{field: '*'},
{field: 'topic()'},
{field: 'topic(2)'},
{field: 'topic(3)'},
{field: 'topic(4)'}
],
topic: '$aws/things/+/shadow/update',
whereClause: `state.reported.mode = 'STAND_BY'`
},
whereEvaluatesTo: true,
event: {
state: {reported: {mode: 'STAND_BY'}},
topic: '$aws/things/+/shadow/update',
'topic(2)': 'things',
'topic(3)': '+',
'topic(4)': 'shadow'
}
}
},
{
sql: `SELECT clientid(), accountid() as account FROM '$aws/events/presence/connected/test_client'`,
payload: `{"event": "connected"}`,
expected: {
parsed: {
select: [{field: 'clientid()'}, {field: 'accountid()', alias: 'account'}],
topic: '$aws/events/presence/connected/test_client'
},
whereEvaluatesTo: true,
event: {
account: 'test_account',
clientid: 'test_client'
}
}
},
{
sql: `SELECT encode(*, 'base64') as encodedPayload FROM '$aws/things/sn:123/shadow/update'`,
payload: `{"state": {"reported": {"mode": "STAND_BY"}}}`,
expected: {
parsed: {
select: [{ field: "encode(*, 'base64')", alias: "encodedPayload" }],
topic: "$aws/things/sn:123/shadow/update",
},
whereEvaluatesTo: true,
event: {
encodedPayload:
"eyJzdGF0ZSI6IHsicmVwb3J0ZWQiOiB7Im1vZGUiOiAiU1RBTkRfQlkifX19",
},
},
},
{
sql: `SELECT encode(state.reported.mode, 'base64') as encodedPayload FROM '$aws/things/sn:123/shadow/update'`,
payload: `{"state": {"reported": {"mode": "STAND_BY"}}}`,
expected: {
parsed: {
select: [
{
field: "encode(state.reported.mode, 'base64')",
alias: "encodedPayload",
},
],
topic: "$aws/things/sn:123/shadow/update",
},
whereEvaluatesTo: true,
event: {
encodedPayload: "U1RBTkRfQlk=",
},
},
}
]