@isTest public with sharing class DeleteOrderFromShopify_Test { @isTest static void TestDeleteOrder(){ account ac = new account(name= 'tesst'); insert ac; order ordobj = new order(); ordobj.Accountid = ac.id; ordobj.EffectiveDate = system.today(); ordobj.HIC_ShopifySync__Shopify_Id__c = '618960158784'; ordobj.Status = 'Draft'; insert ordobj; Opportunity opp = new Opportunity(); opp.Name = 'test'; opp.HIC_ShopifySync__Shopify_Id__c = '618960158784'; opp.CloseDate = system.today(); opp.StageName = 'ClosedWon'; insert opp; HIC_ShopifySync__Order_Fulfillment__c oppful = new HIC_ShopifySync__Order_Fulfillment__c(); oppful.HIC_ShopifySync__Opportunity__c = ordobj.id; oppful.HIC_ShopifySync__Opportunity__c = opp.id; insert oppful; //*************************************************** //CustomSettingRecordInsert.InsertingFieldMapping(); //CustomSettingRecordInsert.InsertingConfiguration(); //CustomSettingRecordInsert.InsertingWebhook(); CustomSettingRecordInsert postinstall = new CustomSettingRecordInsert(); Test.testInstall(postinstall, null); Test.testInstall(postinstall, new Version(1,0), true); //*************************************************** Restrequest req = new Restrequest(); req.requestBody = Blob.valueOf('{ "id": 618960158784, "email": "uv@gmail.com", "closed_at": null, "created_at": "2018-12-21T15:54:18+05:30", "updated_at": "2018-12-21T15:54:18+05:30", "number": 11, "note": "", "token": "7ad316e8c59b1d18877b242d8244eea3", "gateway": "manual", "test": false, "total_price": "5280.50", "subtotal_price": "4475.00", "total_weight": 195, "total_tax": "805.50", "taxes_included": false, "currency": "INR", "financial_status": "paid", "confirmed": true, "total_discounts": "0.00", "total_line_items_price": "4475.00", "cart_token": null, "buyer_accepts_marketing": false, "name": "#1011", "referring_site": null, "landing_site": null, "cancelled_at": "2018-12-21T15:54:18+05:30", "cancel_reason": "N/A", "total_price_usd": "74.70", "checkout_token": null, "reference": null, "user_id": 18963628096, "location_id": null, "source_identifier": null, "source_url": null, "processed_at": "2018-12-21T15:54:18+05:30", "device_id": null, "phone": null, "customer_locale": null, "app_id": 1354745, "browser_ip": null, "landing_site_ref": null, "order_number": 1011, "discount_applications": [], "discount_codes": [], "note_attributes": [], "payment_gateway_names": [ "manual" ], "processing_method": "manual", "checkout_id": null, "source_name": "shopify_draft_order", "fulfillment_status": null, "tax_lines": [ { "price": "805.50", "rate": 0.18, "title": "IGST", "price_set": { "shop_money": { "amount": "805.50", "currency_code": "INR" }, "presentment_money": { "amount": "805.50", "currency_code": "INR" } } } ], "tags": "", "contact_email": "uv@gmail.com", "order_status_url": "https://checkout.shopify.com/10269687872/orders/7ad316e8c59b1d18877b242d8244eea3/authenticate?key=5415e623338fd5f08b77268cc72456b6", "presentment_currency": "INR", "total_line_items_price_set": { "shop_money": { "amount": "4475.00", "currency_code": "INR" }, "presentment_money": { "amount": "4475.00", "currency_code": "INR" } }, "total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "INR" }, "presentment_money": { "amount": "0.00", "currency_code": "INR" } }, "total_shipping_price_set": { "shop_money": { "amount": "0.00", "currency_code": "INR" }, "presentment_money": { "amount": "0.00", "currency_code": "INR" } }, "subtotal_price_set": { "shop_money": { "amount": "4475.00", "currency_code": "INR" }, "presentment_money": { "amount": "4475.00", "currency_code": "INR" } }, "total_price_set": { "shop_money": { "amount": "5280.50", "currency_code": "INR" }, "presentment_money": { "amount": "5280.50", "currency_code": "INR" } }, "total_tax_set": { "shop_money": { "amount": "805.50", "currency_code": "INR" }, "presentment_money": { "amount": "805.50", "currency_code": "INR" } }, "total_tip_received": "0.0", "admin_graphql_api_id": "gid://shopify/Order/618960158784", "line_items": [ { "id": 1468974956608, "variant_id": 17740291244096, "title": "Product", "quantity": 1, "price": "255.00", "sku": "57", "variant_title": "25gm", "vendor": "SyncMyStore", "fulfillment_service": "manual", "product_id": 1799382958144, "requires_shipping": true, "taxable": true, "gift_card": false, "name": "Product - 25gm", "variant_inventory_management": "shopify", "properties": [], "product_exists": true, "fulfillable_quantity": 1, "grams": 55, "total_discount": "0.00", "fulfillment_status": null, "price_set": { "shop_money": { "amount": "255.00", "currency_code": "INR" }, "presentment_money": { "amount": "255.00", "currency_code": "INR" } }, "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "INR" }, "presentment_money": { "amount": "0.00", "currency_code": "INR" } }, "discount_allocations": [], "admin_graphql_api_id": "gid://shopify/LineItem/1468974956608", "tax_lines": [ { "title": "IGST", "price": "45.90", "rate": 0.18, "price_set": { "shop_money": { "amount": "45.90", "currency_code": "INR" }, "presentment_money": { "amount": "45.90", "currency_code": "INR" } } } ] }, { "id": 1468974989376, "variant_id": 17740291342400, "title": "Product", "quantity": 2, "price": "535.00", "sku": "58", "variant_title": "50gm", "vendor": "SyncMyStore", "fulfillment_service": "manual", "product_id": 1799382958144, "requires_shipping": true, "taxable": true, "gift_card": false, "name": "Product - 50gm", "variant_inventory_management": "shopify", "properties": [], "product_exists": true, "fulfillable_quantity": 2, "grams": 55, "total_discount": "0.00", "fulfillment_status": null, "price_set": { "shop_money": { "amount": "535.00", "currency_code": "INR" }, "presentment_money": { "amount": "535.00", "currency_code": "INR" } }, "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "INR" }, "presentment_money": { "amount": "0.00", "currency_code": "INR" } }, "discount_allocations": [], "admin_graphql_api_id": "gid://shopify/LineItem/1468974989376", "tax_lines": [ { "title": "IGST", "price": "192.60", "rate": 0.18, "price_set": { "shop_money": { "amount": "192.60", "currency_code": "INR" }, "presentment_money": { "amount": "192.60", "currency_code": "INR" } } } ] }, { "id": 1468975022144, "variant_id": 17732618125376, "title": "TestProduct", "quantity": 3, "price": "550.00", "sku": "50506", "variant_title": "5mm / black", "vendor": "SyncMyStore", "fulfillment_service": "manual", "product_id": 1798809452608, "requires_shipping": true, "taxable": true, "gift_card": false, "name": "TestProduct - 5mm / black", "variant_inventory_management": "shopify", "properties": [], "product_exists": true, "fulfillable_quantity": 3, "grams": 5, "total_discount": "0.00", "fulfillment_status": null, "price_set": { "shop_money": { "amount": "550.00", "currency_code": "INR" }, "presentment_money": { "amount": "550.00", "currency_code": "INR" } }, "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "INR" }, "presentment_money": { "amount": "0.00", "currency_code": "INR" } }, "discount_allocations": [], "admin_graphql_api_id": "gid://shopify/LineItem/1468975022144", "tax_lines": [ { "title": "IGST", "price": "297.00", "rate": 0.18, "price_set": { "shop_money": { "amount": "297.00", "currency_code": "INR" }, "presentment_money": { "amount": "297.00", "currency_code": "INR" } } } ] }, { "id": 1468975054912, "variant_id": 17732618027072, "title": "TestProduct", "quantity": 3, "price": "500.00", "sku": "50505", "variant_title": "5mm / red", "vendor": "SyncMyStore", "fulfillment_service": "manual", "product_id": 1798809452608, "requires_shipping": true, "taxable": true, "gift_card": false, "name": "TestProduct - 5mm / red", "variant_inventory_management": "shopify", "properties": [], "product_exists": true, "fulfillable_quantity": 3, "grams": 5, "total_discount": "0.00", "fulfillment_status": null, "price_set": { "shop_money": { "amount": "500.00", "currency_code": "INR" }, "presentment_money": { "amount": "500.00", "currency_code": "INR" } }, "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "INR" }, "presentment_money": { "amount": "0.00", "currency_code": "INR" } }, "discount_allocations": [], "admin_graphql_api_id": "gid://shopify/LineItem/1468975054912", "tax_lines": [ { "title": "IGST", "price": "270.00", "rate": 0.18, "price_set": { "shop_money": { "amount": "270.00", "currency_code": "INR" }, "presentment_money": { "amount": "270.00", "currency_code": "INR" } } } ] } ], "shipping_lines": [], "billing_address": { "first_name": "firstname1", "address1": "Noida City Centre Metro Sector 39", "phone": null, "city": "Noida", "zip": "201301", "province": "Uttar Pradesh", "country": "India", "last_name": "lastname1", "address2": "noida", "company": "test", "latitude": 28.57447, "longitude": 77.35561, "name": "firstname1 lastname1", "country_code": "IN", "province_code": "UP" }, "shipping_address": { "first_name": "firstname1", "address1": "Noida City Centre Metro Sector 39", "phone": null, "city": "Noida", "zip": "201301", "province": "Uttar Pradesh", "country": "India", "last_name": "lastname1", "address2": "noida", "company": "test", "latitude": 28.57447, "longitude": 77.35561, "name": "firstname1 lastname1", "country_code": "IN", "province_code": "UP" }, "fulfillments": [], "refunds": [], "customer": { "id": 926016995392, "email": "uv@gmail.com", "accepts_marketing": false, "created_at": "2018-12-12T16:43:59+05:30", "updated_at": "2018-12-21T15:54:18+05:30", "first_name": "firstname1", "last_name": "lastname1", "orders_count": 5, "state": "disabled", "total_spent": "18732.50", "last_order_id": 618960158784, "note": "Noteee", "verified_email": true, "multipass_identifier": null, "tax_exempt": false, "phone": "+918604065624", "tags": "Tagsss", "last_order_name": "#1011", "currency": "INR", "admin_graphql_api_id": "gid://shopify/Customer/926016995392", "default_address": { "id": 1041332338752, "customer_id": 926016995392, "first_name": "firstname1", "last_name": "lastname1", "company": "test", "address1": "Noida City Centre Metro Sector 39", "address2": "noida", "city": "Noida", "province": "Uttar Pradesh", "country": "India", "zip": "201301", "phone": "", "name": "firstname1 lastname1", "province_code": "UP", "country_code": "IN", "country_name": "India", "default": true } } }'); Restresponse res = new Restresponse(); req.requestURI = 'https://hicsfshopify-developer-edition.ap4.force.com/services/apexrest/DeleteOrderFromShopify'; req.httpMethod = 'POST'; RestContext.request = req; RestContext.response= res; res.statusCode = 200; Test.startTest(); DeleteOrderFromShopify.DeleteOrder() ; DeleteOrderFromShopifyAuthentication.deleteOrderWithAuthentication(); Test.stopTest(); system.assertequals(200, res.statuscode); } @isTest static void testDeleteOrderFulfillmentDeletion() { // Create a base Account Account acc = new Account(Name = 'Test Account For Fulfillment'); insert acc; // Create Product and Pricebook setup Product2 prod = new Product2(Name = 'Bat'); insert prod; Id pbId = Test.getStandardPricebookId(); PricebookEntry pbe = new PricebookEntry( IsActive = true, Product2Id = prod.Id, Pricebook2Id = pbId, UnitPrice = 1000 ); insert pbe; // Create an Order that matches Shopify ID Order ord = new Order( AccountId = acc.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pbId, HIC_ShopifySync__Shopify_Id__c = '999888777' ); insert ord; // Add Order Item OrderItem oi = new OrderItem( Product2Id = prod.Id, OrderId = ord.Id, UnitPrice = 1000, Quantity = 1, PricebookEntryId = pbe.Id ); insert oi; // Activate the order to match condition ord.Status = 'Activated'; update ord; // Create Order Fulfillment record related to this Order HIC_ShopifySync__Order_Fulfillment__c fulfillment = new HIC_ShopifySync__Order_Fulfillment__c( Name = 'Test Fulfillment Record', HIC_ShopifySync__Order__c = ord.Id, HIC_ShopifySync__Shopify_Id__c = 'FUL-999' ); insert fulfillment; // Create configuration that enables Order deletion path HIC_ShopifySync__HIC_Configuration__c config = new HIC_ShopifySync__HIC_Configuration__c( Name = 'Default Config', HIC_ShopifySync__Store__c = 'Default', HIC_ShopifySync__Order__c = true, HIC_ShopifySync__Enable_Draft_Order__c = false ); insert config; // Mock REST request & response RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = '/services/apexrest/DeleteOrderFromShopify'; req.httpMethod = 'POST'; req.requestBody = Blob.valueOf('{ "id": 999888777 }'); RestContext.request = req; RestContext.response = res; Test.startTest(); DeleteOrderFromShopify.DeleteOrder(); Test.stopTest(); } @isTest static void testOrgObjSynchUtil2Methods() { Test.startTest(); // Call each static method to verify it runs without exceptions String todayMin = orgObjSynchUtil2.getTodaysBaseTime(); System.assertNotEquals(null, todayMin, 'getTodaysBaseTime() should not return null'); System.assert(todayMin.contains('T'), 'Expected ISO-like datetime format'); String todayMax = orgObjSynchUtil2.getTodaysBaseTimeMax(); System.assertNotEquals(null, todayMax, 'getTodaysBaseTimeMax() should not return null'); String prevHour = orgObjSynchUtil2.getPreviousHour(); System.assertNotEquals(null, prevHour, 'getPreviousHour() should not return null'); String prevHourMax = orgObjSynchUtil2.getPreviousHourMax(); System.assertNotEquals(null, prevHourMax, 'getPreviousHourMax() should not return null'); String currHour = orgObjSynchUtil2.getCurrentHour(); System.assertNotEquals(null, currHour, 'getCurrentHour() should not return null'); String currHourMax = orgObjSynchUtil2.getCurrentHourMax(); System.assertNotEquals(null, currHourMax, 'getCurrentHourMax() should not return null'); String nextHour = orgObjSynchUtil2.getNextHour(); System.assertNotEquals(null, nextHour, 'getNextHour() should not return null'); // Validate that timezone offset format is correct (e.g., +05 or -04) String offset = currHour.substring(currHour.length() - 6, currHour.length() - 3); System.assert(offset.startsWith('+') || offset.startsWith('-'), 'Timezone offset should start with + or -'); Test.stopTest(); } }