|
1 | | -.PHONY: all |
2 | | -all: build |
3 | | - |
4 | | -.PHONY: node_modules |
5 | | -.SILENT: node_modules |
6 | | -node_modules: |
7 | | - npm install |
8 | | - |
9 | | -.PHONY: deploy |
10 | | -.SILENT: deploy |
11 | | -deploy: node_modules |
12 | | - dfx deploy |
13 | | - |
14 | 1 | .PHONY: test |
15 | | -.SILENT: test |
16 | | -test: deploy |
17 | | - $(eval ID := $(shell dfx canister call superheroes create '(record {name = "Superman"; superpowers = vec { "invulnerability"; "superhuman strength" }})' | tr -d '()')) |
18 | | - dfx canister call superheroes read '($(ID))' \ |
19 | | - | grep 'Superman' && echo 'PASS' |
20 | | - dfx canister call superheroes update '($(ID), record {name = "Superman"; superpowers = vec { "invulnerability"; "superhuman strength"; "flight"; "x-ray vision" }})' \ |
21 | | - | grep 'true' && echo 'PASS' |
22 | | - dfx canister call superheroes read '($(ID))' \ |
23 | | - | grep 'x-ray vision' && echo 'PASS' |
24 | | - dfx canister call superheroes delete '($(ID))' \ |
25 | | - | grep 'true' && echo 'PASS' |
26 | | - dfx canister call superheroes delete '($(ID))' \ |
27 | | - | grep 'false' && echo 'PASS' |
28 | | - dfx canister call superheroes read '($(ID))' \ |
29 | | - | grep 'null' && echo 'PASS' |
30 | 2 |
|
31 | | -.PHONY: clean |
32 | | -.SILENT: clean |
33 | | -clean: |
34 | | - rm -fr .dfx |
35 | | - rm -fr node_modules |
| 3 | +# Tests capture the ID from create so they are idempotent across re-runs |
| 4 | +# (the backend uses an auto-incrementing counter, so the ID differs each run). |
| 5 | +test: |
| 6 | + @echo "=== Test 1: create a superhero ===" |
| 7 | + @set -e; \ |
| 8 | + out=$$(icp canister call backend create '(record { name = "Superman"; superpowers = vec { "invulnerability"; "superhuman strength" } })'); \ |
| 9 | + echo "$$out"; \ |
| 10 | + id=$$(echo "$$out" | grep -oE '[0-9]+' | head -1); \ |
| 11 | + [ -n "$$id" ] || (echo "FAIL: could not parse created ID" && exit 1); \ |
| 12 | + echo "Created ID: $$id"; \ |
| 13 | + echo "PASS"; \ |
| 14 | + \ |
| 15 | + echo "=== Test 2: read the created superhero ==="; \ |
| 16 | + result=$$(icp canister call --query backend read "($$id : nat32)"); \ |
| 17 | + echo "$$result"; \ |
| 18 | + echo "$$result" | grep -q 'Superman' && echo "PASS" || (echo "FAIL" && exit 1); \ |
| 19 | + \ |
| 20 | + echo "=== Test 3: update the superhero ==="; \ |
| 21 | + result=$$(icp canister call backend update "($$id : nat32, record { name = \"Superman\"; superpowers = vec { \"invulnerability\"; \"superhuman strength\"; \"flight\"; \"x-ray vision\" } })"); \ |
| 22 | + echo "$$result"; \ |
| 23 | + echo "$$result" | grep -q 'true' && echo "PASS" || (echo "FAIL" && exit 1); \ |
| 24 | + \ |
| 25 | + echo "=== Test 4: read updated superhero to verify state change ==="; \ |
| 26 | + result=$$(icp canister call --query backend read "($$id : nat32)"); \ |
| 27 | + echo "$$result"; \ |
| 28 | + echo "$$result" | grep -q 'x-ray vision' && echo "PASS" || (echo "FAIL" && exit 1); \ |
| 29 | + \ |
| 30 | + echo "=== Test 5: delete the superhero ==="; \ |
| 31 | + result=$$(icp canister call backend delete "($$id : nat32)"); \ |
| 32 | + echo "$$result"; \ |
| 33 | + echo "$$result" | grep -q 'true' && echo "PASS" || (echo "FAIL" && exit 1); \ |
| 34 | + \ |
| 35 | + echo "=== Test 6: delete non-existent superhero returns false ==="; \ |
| 36 | + result=$$(icp canister call backend delete "($$id : nat32)"); \ |
| 37 | + echo "$$result"; \ |
| 38 | + echo "$$result" | grep -q 'false' && echo "PASS" || (echo "FAIL" && exit 1); \ |
| 39 | + \ |
| 40 | + echo "=== Test 7: read deleted superhero returns null ==="; \ |
| 41 | + result=$$(icp canister call --query backend read "($$id : nat32)"); \ |
| 42 | + echo "$$result"; \ |
| 43 | + echo "$$result" | grep -q 'null' && echo "PASS" || (echo "FAIL" && exit 1) |
0 commit comments