Skip to content

Commit

Permalink
Add rule integration tests [CLI-163] (#340)
Browse files Browse the repository at this point in the history
* Add rules integration tests

* Fix tests

* Fix tests

* Rename file

* Update command output

* Fix exit code

* Fix enabled value

* Add cleanup logic

* Move rules cleanup code above roles fro troubleshooting

* Fix typo
  • Loading branch information
Widcket authored Jul 30, 2021
1 parent ee96843 commit 7f578d8
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
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 rule 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

0 comments on commit 7f578d8

Please sign in to comment.