Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
ci(api-contract): seed a network and a second organization (#603)
Ron78ec7794c274
diff --git a/.github/actions/postman-contract/action.yml b/.github/actions/postman-contract/action.ymlindex 25d7a96f..ac04345a 100644--- a/.github/actions/postman-contract/action.yml+++ b/.github/actions/postman-contract/action.yml@@ -159,6 +159,9 @@ runs:STOREFRONT_KEY="$(printf '%s\n' "$OUT" | grep -oE 'MINTED_STOREFRONT_KEY=store_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"INVOICE_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_INVOICE_ID=[A-Za-z0-9_]+' | tail -1 | cut -d= -f2 || true)"GATEWAY_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_LEDGER_GATEWAY=[A-Za-z0-9_]+' | tail -1 | cut -d= -f2 || true)"+ NETWORK_KEY="$(printf '%s\n' "$OUT" | grep -oE 'MINTED_NETWORK_KEY=network_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"+ SECONDARY_ORG_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_SECONDARY_ORGANIZATION_ID=company_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"+ MULTI_ORG_DRIVER_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_DRIVER_ID=driver_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"if [[ -z "$KEY" ]]; thenecho "::error::Could not mint an API key from the running stack. Tinker output:"printf '%s\n' "$OUT"@@ -221,6 +224,18 @@ runs:elseecho "::warning::No payment gateway seeded; the gateway-backed requests will report it as unavailable."fi+ # Network-scoped endpoints need a network session, which a store key cannot give.+ if [[ -n "$NETWORK_KEY" ]]; then+ echo "::add-mask::$NETWORK_KEY"+ echo "network_key=$NETWORK_KEY" >> "$GITHUB_OUTPUT"+ fi+ # Switch Driver Organization needs a driver that belongs to TWO organizations.+ if [[ -n "$SECONDARY_ORG_ID" ]]; then+ echo "secondary_organization_id=$SECONDARY_ORG_ID" >> "$GITHUB_OUTPUT"+ fi+ if [[ -n "$MULTI_ORG_DRIVER_ID" ]]; then+ echo "multi_org_driver_id=$MULTI_ORG_DRIVER_ID" >> "$GITHUB_OUTPUT"+ fiif [[ -n "$PLATFORM_TOKEN" ]]; thenecho "::add-mask::$PLATFORM_TOKEN"echo "platform_token=$PLATFORM_TOKEN" >> "$GITHUB_OUTPUT"@@ -267,6 +282,9 @@ runs:ORGANIZATION_ID: ${{ steps.key.outputs.organization_id }}INVOICE_PUBLIC_ID: ${{ steps.key.outputs.invoice_public_id }}GATEWAY_ID: ${{ steps.key.outputs.gateway_id }}+ NETWORK_KEY: ${{ steps.key.outputs.network_key }}+ SECONDARY_ORG_ID: ${{ steps.key.outputs.secondary_organization_id }}+ MULTI_ORG_DRIVER_ID: ${{ steps.key.outputs.multi_org_driver_id }}COLLECTIONS: ${{ inputs.collections }}BASE_URL: ${{ inputs.base-url }}NAMESPACE: ${{ inputs.namespace }}@@ -346,6 +364,9 @@ runs:' --env-var "proof_signature_base64=iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAbElEQVR42hXNQRUAUQhCUaMYhShGeVGIQhSizB+XXA7ODDtouIHBQ4YOM8suWm5h8ZKl+0CskDiBsIioHhx76LiDw0eO3oN/4FVf+J8h0PduzBqZ8x/bxNQPwgaFy192SGgelC0q13/CJaXlA8Z7WAFXOTbyAAAAAElFTkSuQmCC" \' \' --env-var "invoice_public_id=${INVOICE_PUBLIC_ID}" \' \' --env-var "gateway_id=${GATEWAY_ID}" \' \+ ' --env-var "network_key=${NETWORK_KEY}" \' \+ ' --env-var "secondary_organization_id=${SECONDARY_ORG_ID}" \' \+ ' --env-var "multi_org_driver_id=${MULTI_ORG_DRIVER_ID}" \' \' --env-var "payment_reference=ci-contract-payment-reference" \' \' --env-var "push_token=ci-contract-push-token" \' \' "${@:2}"' > "$RUNNER"diff --git a/scripts/ci/mint-api-key.php b/scripts/ci/mint-api-key.phpindex eaf0ae0c..53ffa762 100644--- a/scripts/ci/mint-api-key.php+++ b/scripts/ci/mint-api-key.php@@ -274,9 +274,73 @@ try {$driverCode->code = $customerCode;$driverCode->save();+ /* ============================================================+ | SECOND ORGANIZATION (Switch Driver Organization)+ * ============================================================ */++ // switchOrganization rejects a switch to the org the driver is already in, and then+ // requires a CompanyUser row proving membership of the target. Neither can be created+ // through the public API, so the seeded driver is given a second organization here:+ // a company, a CompanyUser row, and a driver profile in it.+ //+ // The collection's other driver requests use {{driver_id}} from Create a Driver, whose+ // user belongs to one company only — hence a separate {{multi_org_driver_id}} for the+ // one request that needs two.+ $secondCompany = \Fleetbase\Models\Company::firstOrCreate(['name' => 'CI Contract Org (Secondary)']);+ if (empty($secondCompany->owner_uuid)) {+ $secondCompany->setOwner($user, true);+ $secondCompany->save();+ }++ \Fleetbase\Models\CompanyUser::firstOrCreate([+ 'company_uuid' => $secondCompany->uuid,+ 'user_uuid' => $driverUser->uuid,+ ], ['status' => 'active']);++ if (class_exists(\Fleetbase\FleetOps\Models\Driver::class)) {+ \Fleetbase\FleetOps\Models\Driver::firstOrCreate(+ ['user_uuid' => $driverUser->uuid, 'company_uuid' => $secondCompany->uuid],+ ['status' => 'active', 'online' => 0]+ );+ }++ echo 'SEEDED_SECONDARY_ORGANIZATION_ID=' . $secondCompany->public_id . PHP_EOL;+echo 'SEEDED_DRIVER_IDENTITY=' . $driverIdentity . PHP_EOL;echo 'SEEDED_DRIVER_PHONE=' . $driverPhone . PHP_EOL;+ /* ============================================================+ | NETWORK (Storefront network-scoped endpoints)+ * ============================================================ */++ // List Network Stores answered "Stores cannot have stores!" because the contract+ // authenticates with a STORE key, and the network endpoints require a network session.+ // Network::boot() generates `key = 'network_' . md5(...)` on insert exactly like Store,+ // so a seeded network yields a usable key; the collection's network requests send it+ // instead of the store key.+ if (isset($store) && class_exists(\Fleetbase\Storefront\Models\Network::class)) {+ $network = \Fleetbase\Storefront\Models\Network::withoutGlobalScopes()+ ->where(['company_uuid' => $company->uuid, 'name' => 'CI Contract Network'])+ ->first();++ if (!$network) {+ $network = \Fleetbase\Storefront\Models\Network::create([+ 'company_uuid' => $company->uuid,+ 'created_by_uuid' => $user->uuid,+ 'name' => 'CI Contract Network',+ 'description' => 'Seeded by the API contract run.',+ 'currency' => 'USD',+ 'online' => 1,+ ]);+ }++ // Without a member store the listing is empty and proves nothing.+ $network->addStore($store);++ echo 'MINTED_NETWORK_KEY=' . $network->fresh()->key . PHP_EOL;+ echo 'MINTED_NETWORK_ID=' . $network->public_id . PHP_EOL;+ }+/* ============================================================| STORE LOCATION (Storefront)* ============================================================ */