|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Round-trip smoke test for the get-all command |
| 4 | +# 1. Create resources from different families |
| 5 | +# 2. Export them with a single get-all --output-format epcc-cli |
| 6 | +# 3. Delete the resources |
| 7 | +# 4. Run the exported script to recreate them |
| 8 | +# 5. Verify resources were recreated |
| 9 | + |
| 10 | +set -e |
| 11 | + |
| 12 | +TEMP_DIR=$(mktemp -d) |
| 13 | + |
| 14 | +cleanup() { |
| 15 | + rm -rf "$TEMP_DIR" |
| 16 | +} |
| 17 | +trap cleanup EXIT |
| 18 | + |
| 19 | +echo "=== get-all Round-Trip Smoke Test ===" |
| 20 | +epcc reset-store .+ |
| 21 | + |
| 22 | +# Step 1: Create resources from different families |
| 23 | +echo "=== Step 1: Creating test resources ===" |
| 24 | + |
| 25 | +# Account and sub-resource (account-address) |
| 26 | +epcc create account name "get-all-test-account" legal_name "Test Account for get-all" |
| 27 | +epcc create account-address account/name=get-all-test-account name "Test Address" first_name "John" last_name "Doe" line_1 "123 Test St" city "Test City" postcode "H0H 0H0" county "Test County" country "US" |
| 28 | + |
| 29 | +# Customer |
| 30 | +epcc create customer name "get-all-test-customer" email "get-all-test@example.com" |
| 31 | + |
| 32 | + |
| 33 | +# Custom API with fields and entry |
| 34 | +epcc create custom-api name "smoke-test-api" slug "smoke-test-api" api_type "smoke_test_ext" description "Smoke test API" |
| 35 | +epcc create custom-field custom_api/slug=smoke-test-api name "test_string" description blah slug "test_string" field_type "string" |
| 36 | +epcc create custom-field custom_api/slug=smoke-test-api name "test_int" description blah slug "test_int" field_type "integer" |
| 37 | +epcc create custom-field custom_api/slug=smoke-test-api name "test_bool" description blah slug "test_bool" field_type "boolean" |
| 38 | +epcc create custom-api-settings-entry custom_api/slug=smoke-test-api data.test_string "hello world" data.test_int 42 data.test_bool true data.type "smoke_test_ext" |
| 39 | + |
| 40 | +# PCM resources with hierarchy and node-product relationships |
| 41 | +epcc create pcm-product --auto-fill name "Smoke Test Product" |
| 42 | +epcc create pcm-hierarchy name "smoke-test-hierarchy" |
| 43 | +epcc create pcm-node name=smoke-test-hierarchy name "Parent Node" --auto-fill |
| 44 | +epcc create pcm-node name=smoke-test-hierarchy name "Child Node" --auto-fill relationships.parent.data.id name=Parent_Node |
| 45 | +epcc create pcm-node-product name=smoke-test-hierarchy name=Child_Node data\[0\].id last_read=entity |
| 46 | + |
| 47 | +echo "=== Step 2: Export all resources with single get-all ===" |
| 48 | + |
| 49 | +epcc get-all accounts account-addresses customers custom-apis custom-fields custom-api-settings-entries \ |
| 50 | + pcm-products pcm-hierarchies pcm-nodes pcm-node-products \ |
| 51 | + --output-file "$TEMP_DIR/export.sh" --output-format epcc-cli --truncate-output |
| 52 | + |
| 53 | +echo "=== Step 3: Delete resources ===" |
| 54 | + |
| 55 | +# Delete in reverse dependency order |
| 56 | +epcc delete-all custom-api-settings-entries |
| 57 | +epcc delete-all custom-fields |
| 58 | +epcc delete-all custom-apis |
| 59 | +epcc delete-all customers |
| 60 | +epcc delete-all account-addresses |
| 61 | +epcc delete-all accounts |
| 62 | +epcc delete-all pcm-nodes |
| 63 | +epcc delete-all pcm-hierarchies |
| 64 | +epcc delete-all pcm-products |
| 65 | + |
| 66 | +echo "=== Step 4: Run exported script to recreate resources ===" |
| 67 | + |
| 68 | +"$TEMP_DIR/export.sh" |
| 69 | + |
| 70 | +echo "=== Step 5: Verify resources were recreated ===" |
| 71 | + |
| 72 | +# Check account exists (use collection query since aliases aren't saved with --skip-alias-processing) |
| 73 | +# Note: --output-jq returns JSON-formatted values (strings have quotes), so we strip them with tr |
| 74 | +ACCOUNT_ID=$(epcc get accounts --output-jq '.data[] | select(.name == "get-all-test-account") | .id' 2>/dev/null | tr -d '"' || echo "") |
| 75 | +if [ -z "$ACCOUNT_ID" ]; then |
| 76 | + echo "FAIL: Account get-all-test-account not found after recreation" |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | +echo "PASS: Account recreated (id: $ACCOUNT_ID)" |
| 80 | + |
| 81 | +# Check account-address exists (use ID since aliases aren't saved with --skip-alias-processing) |
| 82 | +ADDRESS_COUNT=$(epcc get account-addresses "$ACCOUNT_ID" --output-jq '.meta.results.total' 2>/dev/null | tr -d '"' || echo "0") |
| 83 | +if [ "$ADDRESS_COUNT" -lt 1 ]; then |
| 84 | + echo "FAIL: No account-addresses found after recreation" |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | +echo "PASS: Account-addresses recreated ($ADDRESS_COUNT found)" |
| 88 | + |
| 89 | +# Check customer exists |
| 90 | +CUSTOMER_COUNT=$(epcc get customers --output-jq '.meta.results.total' | tr -d '"') |
| 91 | +if [ "$CUSTOMER_COUNT" -lt 1 ]; then |
| 92 | + echo "FAIL: No customers found after recreation" |
| 93 | + exit 1 |
| 94 | +fi |
| 95 | +echo "PASS: Customers recreated ($CUSTOMER_COUNT found)" |
| 96 | + |
| 97 | +# Check custom-api exists (use collection query since aliases aren't saved with --skip-alias-processing) |
| 98 | +CUSTOM_API_ID=$(epcc get custom-apis --output-jq '.data[] | select(.slug == "smoke-test-api") | .id' 2>/dev/null | tr -d '"' || echo "") |
| 99 | +if [ -z "$CUSTOM_API_ID" ]; then |
| 100 | + echo "FAIL: Custom API smoke-test-api not found after recreation" |
| 101 | + epcc get custom-apis |
| 102 | + exit 1 |
| 103 | +fi |
| 104 | +echo "PASS: Custom API recreated (id: $CUSTOM_API_ID)" |
| 105 | + |
| 106 | +# Check custom-fields exist (use ID since aliases aren't saved with --skip-alias-processing) |
| 107 | +FIELD_COUNT=$(epcc get custom-fields "$CUSTOM_API_ID" --output-jq '.meta.results.total' 2>/dev/null | tr -d '"' || echo "0") |
| 108 | +if [ "$FIELD_COUNT" -lt 3 ]; then |
| 109 | + echo "FAIL: Expected at least 3 custom-fields, found $FIELD_COUNT" |
| 110 | + exit 1 |
| 111 | +fi |
| 112 | +echo "PASS: Custom fields recreated ($FIELD_COUNT found)" |
| 113 | + |
| 114 | +# Check custom-api-settings-entry exists (use ID since aliases aren't saved with --skip-alias-processing) |
| 115 | +ENTRY_COUNT=$(epcc get custom-api-settings-entries "$CUSTOM_API_ID" --output-jq '.meta.results.total' 2>/dev/null | tr -d '"' || echo "0") |
| 116 | +if [ "$ENTRY_COUNT" -lt 1 ]; then |
| 117 | + echo "FAIL: No custom-api-settings-entries found after recreation" |
| 118 | + exit 1 |
| 119 | +fi |
| 120 | +echo "PASS: Custom API entries recreated ($ENTRY_COUNT found)" |
| 121 | + |
| 122 | +# Check pcm-product exists |
| 123 | +PRODUCT_ID=$(epcc get pcm-products --output-jq '.data[] | select(.attributes.name == "Smoke Test Product") | .id' 2>/dev/null | tr -d '"' || echo "") |
| 124 | +if [ -z "$PRODUCT_ID" ]; then |
| 125 | + echo "FAIL: PCM product 'Smoke Test Product' not found after recreation" |
| 126 | + exit 1 |
| 127 | +fi |
| 128 | +echo "PASS: PCM product recreated (id: $PRODUCT_ID)" |
| 129 | + |
| 130 | +# Check pcm-hierarchy exists |
| 131 | +HIERARCHY_ID=$(epcc get pcm-hierarchies --output-jq '.data[] | select(.attributes.name == "smoke-test-hierarchy") | .id' 2>/dev/null | tr -d '"' || echo "") |
| 132 | +if [ -z "$HIERARCHY_ID" ]; then |
| 133 | + echo "FAIL: PCM hierarchy 'smoke-test-hierarchy' not found after recreation" |
| 134 | + exit 1 |
| 135 | +fi |
| 136 | +echo "PASS: PCM hierarchy recreated (id: $HIERARCHY_ID)" |
| 137 | + |
| 138 | +# Check pcm-nodes exist |
| 139 | +NODE_COUNT=$(epcc get pcm-nodes "$HIERARCHY_ID" --output-jq '.data | length' 2>/dev/null | tr -d '"' || echo "0") |
| 140 | +if [ "$NODE_COUNT" -lt 2 ]; then |
| 141 | + echo "FAIL: Expected at least 2 pcm-nodes, found $NODE_COUNT" |
| 142 | + exit 1 |
| 143 | +fi |
| 144 | +echo "PASS: PCM nodes recreated ($NODE_COUNT found)" |
| 145 | + |
| 146 | +# Check pcm-node-products exist (get child node ID first) |
| 147 | +CHILD_NODE_ID=$(epcc get pcm-nodes "$HIERARCHY_ID" --output-jq '.data[] | select(.attributes.name == "Child Node") | .id' 2>/dev/null | tr -d '"' || echo "") |
| 148 | +if [ -n "$CHILD_NODE_ID" ]; then |
| 149 | + NODE_PRODUCT_COUNT=$(epcc get pcm-node-products "$HIERARCHY_ID" "$CHILD_NODE_ID" --output-jq '.data | length' 2>/dev/null | tr -d '"' || echo "0") |
| 150 | + if [ "$NODE_PRODUCT_COUNT" -lt 1 ]; then |
| 151 | + echo "FAIL: No pcm-node-products found after recreation" |
| 152 | + exit 1 |
| 153 | + fi |
| 154 | + echo "PASS: PCM node-products recreated ($NODE_PRODUCT_COUNT found)" |
| 155 | +else |
| 156 | + echo "FAIL: Child node not found for pcm-node-products verification" |
| 157 | + exit 1 |
| 158 | +fi |
| 159 | + |
| 160 | +echo "" |
| 161 | +echo "=== get-all Round-Trip Smoke Test PASSED ===" |
0 commit comments