feat: integrate Rybbit analytics alongside OpenPanel
Some checks failed
Build and Deploy / build (push) Has been cancelled
Some checks failed
Build and Deploy / build (push) Has been cancelled
- Add RybbitService for tracking e-commerce events - Update useAnalytics hook to track with both OpenPanel and Rybbit - Add Rybbit script to layout for page view tracking - Track all applicable store events: product views, cart, checkout, orders, search, etc.
This commit is contained in:
232
scripts/test-order-creation.js
Normal file
232
scripts/test-order-creation.js
Normal file
@@ -0,0 +1,232 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Full order creation test via API
|
||||
* Tests complete checkout flow including order completion
|
||||
*/
|
||||
|
||||
const SALEOR_API_URL = 'https://api.manoonoils.com/graphql/';
|
||||
|
||||
async function saleorFetch(query, variables = {}) {
|
||||
const response = await fetch(SALEOR_API_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ query: query.replace(/\n\s*/g, ' '), variables }),
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.errors) {
|
||||
console.error('GraphQL Error:', JSON.stringify(result.errors, null, 2));
|
||||
throw new Error(result.errors[0].message);
|
||||
}
|
||||
return result.data;
|
||||
}
|
||||
|
||||
async function runOrderTest() {
|
||||
console.log('🧪 FULL ORDER CREATION TEST ON DEV BRANCH\n');
|
||||
console.log('=' .repeat(60));
|
||||
|
||||
try {
|
||||
// STEP 1: Create checkout
|
||||
console.log('\n📦 STEP 1: Create Checkout');
|
||||
const createResult = await saleorFetch(`
|
||||
mutation CheckoutCreate($input: CheckoutCreateInput!) {
|
||||
checkoutCreate(input: $input) {
|
||||
checkout {
|
||||
id
|
||||
token
|
||||
totalPrice { gross { amount currency } }
|
||||
}
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, {
|
||||
input: {
|
||||
channel: "default-channel",
|
||||
email: "test-order@example.com",
|
||||
lines: [],
|
||||
languageCode: "SR"
|
||||
}
|
||||
});
|
||||
|
||||
const checkoutId = createResult.checkoutCreate.checkout.id;
|
||||
console.log('✅ Checkout created:', checkoutId);
|
||||
|
||||
// STEP 2: Get product and add to cart
|
||||
console.log('\n🛒 STEP 2: Add Product');
|
||||
const productsResult = await saleorFetch(`
|
||||
query {
|
||||
products(channel: "default-channel", first: 1) {
|
||||
edges { node { variants { id name } } }
|
||||
}
|
||||
}
|
||||
`);
|
||||
const variantId = productsResult.products.edges[0].node.variants[0].id;
|
||||
|
||||
await saleorFetch(`
|
||||
mutation CheckoutLinesAdd($checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
|
||||
checkoutLinesAdd(checkoutId: $checkoutId, lines: $lines) {
|
||||
checkout { id }
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, {
|
||||
checkoutId: checkoutId,
|
||||
lines: [{ variantId: variantId, quantity: 1 }]
|
||||
});
|
||||
console.log('✅ Product added');
|
||||
|
||||
// STEP 3: Update email
|
||||
console.log('\n📧 STEP 3: Update Email');
|
||||
await saleorFetch(`
|
||||
mutation CheckoutEmailUpdate($checkoutId: ID!, $email: String!) {
|
||||
checkoutEmailUpdate(checkoutId: $checkoutId, email: $email) {
|
||||
checkout { id }
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, { checkoutId: checkoutId, email: "test-order@example.com" });
|
||||
console.log('✅ Email updated');
|
||||
|
||||
// STEP 4: Set shipping address
|
||||
console.log('\n📍 STEP 4: Set Shipping Address');
|
||||
await saleorFetch(`
|
||||
mutation CheckoutShippingAddressUpdate($checkoutId: ID!, $shippingAddress: AddressInput!) {
|
||||
checkoutShippingAddressUpdate(checkoutId: $checkoutId, shippingAddress: $shippingAddress) {
|
||||
checkout {
|
||||
id
|
||||
shippingMethods { id name price { amount } }
|
||||
}
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, {
|
||||
checkoutId: checkoutId,
|
||||
shippingAddress: {
|
||||
firstName: "Test",
|
||||
lastName: "User",
|
||||
streetAddress1: "123 Test Street",
|
||||
city: "Belgrade",
|
||||
postalCode: "11000",
|
||||
country: "RS",
|
||||
phone: "+38160123456"
|
||||
}
|
||||
});
|
||||
|
||||
// Get shipping methods
|
||||
const methodsResult = await saleorFetch(`
|
||||
query GetCheckout($token: UUID!) {
|
||||
checkout(token: $token) {
|
||||
shippingMethods { id name price { amount } }
|
||||
}
|
||||
}
|
||||
`, { token: createResult.checkoutCreate.checkout.token });
|
||||
|
||||
const shippingMethodId = methodsResult.checkout.shippingMethods[0].id;
|
||||
console.log('✅ Address set, shipping method available:', methodsResult.checkout.shippingMethods[0].name);
|
||||
|
||||
// STEP 5: Set billing address
|
||||
console.log('\n💳 STEP 5: Set Billing Address');
|
||||
await saleorFetch(`
|
||||
mutation CheckoutBillingAddressUpdate($checkoutId: ID!, $billingAddress: AddressInput!) {
|
||||
checkoutBillingAddressUpdate(checkoutId: $checkoutId, billingAddress: $billingAddress) {
|
||||
checkout { id }
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, {
|
||||
checkoutId: checkoutId,
|
||||
billingAddress: {
|
||||
firstName: "Test",
|
||||
lastName: "User",
|
||||
streetAddress1: "123 Test Street",
|
||||
city: "Belgrade",
|
||||
postalCode: "11000",
|
||||
country: "RS",
|
||||
phone: "+38160123456"
|
||||
}
|
||||
});
|
||||
console.log('✅ Billing address set');
|
||||
|
||||
// STEP 6: Select shipping method
|
||||
console.log('\n🚚 STEP 6: Select Shipping Method');
|
||||
await saleorFetch(`
|
||||
mutation CheckoutShippingMethodUpdate($checkoutId: ID!, $shippingMethodId: ID!) {
|
||||
checkoutShippingMethodUpdate(checkoutId: $checkoutId, shippingMethodId: $shippingMethodId) {
|
||||
checkout {
|
||||
id
|
||||
totalPrice { gross { amount } }
|
||||
subtotalPrice { gross { amount } }
|
||||
shippingPrice { gross { amount } }
|
||||
}
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, { checkoutId: checkoutId, shippingMethodId: shippingMethodId });
|
||||
console.log('✅ Shipping method selected');
|
||||
|
||||
// STEP 7: Complete checkout (create order)
|
||||
console.log('\n✅ STEP 7: Complete Checkout (Create Order)');
|
||||
console.log('-'.repeat(60));
|
||||
|
||||
const completeResult = await saleorFetch(`
|
||||
mutation CheckoutComplete($checkoutId: ID!) {
|
||||
checkoutComplete(checkoutId: $checkoutId) {
|
||||
order {
|
||||
id
|
||||
number
|
||||
status
|
||||
created
|
||||
total {
|
||||
gross { amount currency }
|
||||
}
|
||||
subtotal {
|
||||
gross { amount }
|
||||
}
|
||||
shippingPrice {
|
||||
gross { amount }
|
||||
}
|
||||
}
|
||||
errors { field message }
|
||||
}
|
||||
}
|
||||
`, { checkoutId: checkoutId });
|
||||
|
||||
if (completeResult.checkoutComplete.errors?.length > 0) {
|
||||
throw new Error(`Order creation failed: ${completeResult.checkoutComplete.errors[0].message}`);
|
||||
}
|
||||
|
||||
const order = completeResult.checkoutComplete.order;
|
||||
|
||||
console.log('✅ ORDER CREATED SUCCESSFULLY!');
|
||||
console.log('');
|
||||
console.log('Order Details:');
|
||||
console.log(' Order ID:', order.id);
|
||||
console.log(' Order Number:', order.number);
|
||||
console.log(' Status:', order.status);
|
||||
console.log(' Created:', order.created);
|
||||
console.log('');
|
||||
console.log('Pricing:');
|
||||
console.log(' Subtotal:', order.subtotal.gross.amount, 'RSD');
|
||||
console.log(' Shipping:', order.shippingPrice.gross.amount, 'RSD');
|
||||
console.log(' Total:', order.total.gross.amount, 'RSD');
|
||||
|
||||
// Verification
|
||||
const expectedTotal = order.subtotal.gross.amount + order.shippingPrice.gross.amount;
|
||||
console.log('');
|
||||
console.log('📊 VERIFICATION:');
|
||||
if (order.total.gross.amount === expectedTotal) {
|
||||
console.log('✅ PASS: Order total includes shipping correctly');
|
||||
console.log(` ${order.subtotal.gross.amount} + ${order.shippingPrice.gross.amount} = ${order.total.gross.amount}`);
|
||||
} else {
|
||||
console.log('❌ FAIL: Order total does not match expected');
|
||||
}
|
||||
|
||||
console.log('');
|
||||
console.log('🎉 DEV BRANCH TEST COMPLETE - ALL SYSTEMS GO!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Test failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
runOrderTest();
|
||||
Reference in New Issue
Block a user