Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule integration tests [CLI-163] #340

Merged
merged 11 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions commander.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,72 @@ tests:
json:
description: betterDescription
exit-code: 0

# Test 'rules create'
rules create and check data:
command: cat ./integration/fixtures/create-rule.json | jq '.[0]' | auth0 rules create --format json
stdout:
json:
name: integration-test-rule-new1
enabled: "true"
order: "1"
script: "function(user, context, cb) {\n cb(null, user, context);\n}\n"
exit-code: 0

rules create and check output:
command: cat ./integration/fixtures/create-rule.json | jq '.[1]' | auth0 rules create
stdout:
contains:
- NAME integration-test-rule-new2
- ENABLED ✗
- ORDER 2
- SCRIPT function(user, context, cb) {
exit-code: 0

# Test 'rules show'
rules create test rule:
command: ./integration/get-rule-id.sh
exit-code: 0

rules show json:
command: auth0 rules show $(cat ./integration/identifiers/rule-id) --format json
stdout:
json:
name: integration-test-rule-newRule
enabled: "true"
order: "3"
exit-code: 0

rules show:
command: auth0 rules show $(cat ./integration/identifiers/rule-id)
stdout:
contains:
- NAME integration-test-rule-newRule
- ENABLED ✓
- ORDER 3
exit-code: 0

# Test 'rules update'
rules update:
command: cat ./integration/fixtures/update-rule.json | auth0 rules update --format json
stdout:
json:
name: integration-test-rule-betterName
enabled: "false"
exit-code: 0

# Test 'rules enable'
rules enable:
command: auth0 rules enable $(cat ./integration/identifiers/rule-id) --format json
stdout:
json:
enabled: "true"
exit-code: 0

# Test 'rules disable'
rules disable:
command: auth0 rules disable $(cat ./integration/identifiers/rule-id) --format json
stdout:
json:
enabled: "false"
exit-code: 0
12 changes: 12 additions & 0 deletions integration/fixtures/create-rule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"name": "integration-test-rule-new1",
"script": "function(user, context, cb) {\n cb(null, user, context);\n}\n",
"enabled": true
},
{
"name": "integration-test-rule-new2",
"script": "function(user, context, cb) {\n cb(null, user, context);\n}\n",
"enabled": false
}
]
8 changes: 8 additions & 0 deletions integration/get-rule-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

json='{"name":"integration-test-rule-newRule","script":"function(user, context, cb) {\n cb(null, user, context);\n}\n","enabled":false}'
rule=$( echo "$json" | auth0 rules create --format json )

mkdir -p ./integration/identifiers
echo "$rule" | jq -r '.["id"]' > ./integration/identifiers/rule-id
echo "$rule" | jq '.name = "integration-test-rule-betterName"' | jq '.enabled = false' > ./integration/fixtures/update-rule.json
18 changes: 18 additions & 0 deletions integration/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,21 @@ for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do
$( auth0 roles delete "$id")
fi
done

rules=$( auth0 rules list --format json --no-input )

for rules in $( echo "${rules}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${rule}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')
# TODO(jfatta): should remove only those
# created during the same test session
if [[ $name = integration-test-rule-* ]]
then
echo deleting "$name"
$( auth0 rules delete "$id")
fi
done