orcli/tests/export-template.sh

31 lines
875 B
Bash
Raw Normal View History

2023-01-27 18:04:27 +01:00
#!/bin/bash
# shellcheck disable=SC1083
t="export-template"
# create tmp directory
tmpdir="$(mktemp -d)"
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
# input
cp data/duplicates.csv "${tmpdir}/${t}.csv"
# assertion
cat << "DATA" > "${tmpdir}/${t}.assert"
2023-10-26 01:25:40 +02:00
{ "events" : [{ "name" : "Ben Tyler", "purchase" : "Flashlight" },{ "name" : "Ben Morisson", "purchase" : "Amplifier" }]}
2023-01-27 18:04:27 +01:00
DATA
# action
cd "${tmpdir}" || exit 1
orcli import csv "${t}.csv" --projectName "${t}"
orcli export template "${t}" --output "${t}.output" \
<<< '{ "name" : {{jsonize(cells["name"].value)}}, "purchase" : {{jsonize(cells["purchase"].value)}} }' \
--prefix '{ "events" : [' \
--separator , \
2023-10-26 01:25:40 +02:00
--mode records \
2023-01-27 18:04:27 +01:00
--suffix ]}$'\n' \
--facets '[ { "type": "text", "name": "foo", "columnName": "name", "mode": "regex", "caseSensitive": false, "query": "Ben" } ]'
# test
diff -u "${t}.assert" "${t}.output"