SyncMadeEasy/force-app/main/default/classes/CreateShopifyLogTest.cls

230 lines
36 KiB
OpenEdge ABL

@isTest
private class CreateShopifyLogTest {
@isTest
static void testCreateLog2() {
Map<String, Object> jsonMap = new Map<String, Object>();
jsonMap.put('id', '618960158784');
List<Object> testList = new List<Object>();
String reqBody = '{"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 } } } ';
for(Integer i = 0; i<=45; i++){
testList.add(reqBody);
}
jsonMap.put('bodyList', testList);
String requestBody = JSON.serialize(jsonMap);
System.debug('>> THIS IS THE LENGTH :: '+requestBody.length());
Map<String, String> params = new Map<String, String>();
params.put('store', 'TestStore');
params.put('objectname', 'TestObject');
RestRequest request = new RestRequest();
request.params.put('store', '{"store":"TestStore", "objectname":"TestObject"}');
request.requestURI = '/CreateShopifyLog';
request.httpMethod = 'POST';
request.requestBody = Blob.valueOf(requestBody);
RestResponse response = new RestResponse();
Test.startTest();
RestContext.request = request;
RestContext.response = response;
CreateShopifyLog.createlog();
System.assertEquals(null, response.statusCode);
List<HIC_ShopifySync__Shopify_Log__c> successLogs = [
SELECT HIC_ShopifySync__Info__c, HIC_ShopifySync__Second_Info__c, HIC_ShopifySync__Third_Info__c
FROM HIC_ShopifySync__Shopify_Log__c
LIMIT 1
];
System.assertEquals(1, successLogs.size());
HIC_ShopifySync__Shopify_Log__c successLog = successLogs[0];
Integer lengthofJSONResponseBody = requestBody.length();
if (lengthofJSONResponseBody > 131072 && lengthofJSONResponseBody <= 262144) {
System.assertEquals(requestBody.substring(0, 131072), successLog.HIC_ShopifySync__Info__c);
System.assertEquals(requestBody.substring(131072, lengthofJSONResponseBody), successLog.HIC_ShopifySync__Second_Info__c);
} else {
//System.assertEquals(requestBody, successLog.HIC_ShopifySync__Info__c);
}
Test.stopTest();
}
@isTest
static void testCreateLog1() {
Map<String, Object> jsonMap = new Map<String, Object>();
jsonMap.put('id', '618960158784');
List<Object> testList = new List<Object>();
String reqBody = '{"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 } } } ';
for(Integer i = 0; i<=25; i++){
testList.add(reqBody);
}
jsonMap.put('bodyList', testList);
String requestBody = JSON.serialize(jsonMap);
System.debug('>> THIS IS THE LENGTH :: '+requestBody.length());
Map<String, String> params = new Map<String, String>();
params.put('store', 'TestStore');
params.put('objectname', 'TestObject');
RestRequest request = new RestRequest();
request.params.put('store', '{"store":"TestStore", "objectname":"TestObject"}');
request.requestURI = '/CreateShopifyLog';
request.httpMethod = 'POST';
request.requestBody = Blob.valueOf(requestBody);
RestResponse response = new RestResponse();
Test.startTest();
RestContext.request = request;
RestContext.response = response;
CreateShopifyLog.createlog();
System.assertEquals(null, response.statusCode);
List<HIC_ShopifySync__Shopify_Log__c> successLogs = [
SELECT HIC_ShopifySync__Info__c, HIC_ShopifySync__Second_Info__c, HIC_ShopifySync__Third_Info__c
FROM HIC_ShopifySync__Shopify_Log__c
LIMIT 1
];
System.assertEquals(1, successLogs.size());
HIC_ShopifySync__Shopify_Log__c successLog = successLogs[0];
Integer lengthofJSONResponseBody = requestBody.length();
if (lengthofJSONResponseBody > 131072 && lengthofJSONResponseBody <= 262144) {
System.assertEquals(requestBody.substring(0, 131072), successLog.HIC_ShopifySync__Info__c);
System.assertEquals(requestBody.substring(131072, lengthofJSONResponseBody), successLog.HIC_ShopifySync__Second_Info__c);
} else {
//System.assertEquals(requestBody, successLog.HIC_ShopifySync__Info__c);
}
Test.stopTest();
}
@isTest
static void testCreateLog43() {
Map<String, Object> jsonMap = new Map<String, Object>();
jsonMap.put('id', '618960158784');
List<Object> testList = new List<Object>();
String reqBody = '{"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 } } } ';
for(Integer i = 0; i<=15; i++){
testList.add(reqBody);
}
jsonMap.put('bodyList', testList);
String requestBody = JSON.serialize(jsonMap);
System.debug('>> THIS IS THE LENGTH :: '+requestBody.length());
Map<String, String> params = new Map<String, String>();
params.put('store', 'TestStore');
params.put('objectname', 'TestObject');
RestRequest request = new RestRequest();
request.params.put('store', '{"store":"TestStore", "objectname":"TestObject"}');
request.requestURI = '/CreateShopifyLog';
request.httpMethod = 'POST';
request.requestBody = Blob.valueOf(requestBody);
RestResponse response = new RestResponse();
Test.startTest();
RestContext.request = request;
RestContext.response = response;
CreateShopifyLog.createlog();
System.assertEquals(null, response.statusCode);
List<HIC_ShopifySync__Shopify_Log__c> successLogs = [
SELECT HIC_ShopifySync__Info__c, HIC_ShopifySync__Second_Info__c, HIC_ShopifySync__Third_Info__c
FROM HIC_ShopifySync__Shopify_Log__c
LIMIT 1
];
System.assertEquals(1, successLogs.size());
HIC_ShopifySync__Shopify_Log__c successLog = successLogs[0];
Integer lengthofJSONResponseBody = requestBody.length();
if (lengthofJSONResponseBody > 262144) {
System.assertEquals(requestBody.substring(0, 131072), successLog.HIC_ShopifySync__Info__c);
System.assertEquals(requestBody.substring(131072, Math.min(lengthofJSONResponseBody, 262144)), successLog.HIC_ShopifySync__Second_Info__c);
System.assertEquals(requestBody.substring(262144, Math.min(lengthofJSONResponseBody, 262144)), successLog.HIC_ShopifySync__Third_Info__c);
} else {
//System.assertEquals(requestBody, successLog.HIC_ShopifySync__Info__c);
}
Test.stopTest();
}
@testSetup
static void setupData() {
List<HIC_ShopifySync__shopify_log__c> allLogs = new List<HIC_ShopifySync__shopify_log__c>();
for (Integer i = 0; i < 5; i++) {
allLogs.add(new HIC_ShopifySync__shopify_log__c(Name = 'Log ' + i));
}
insert allLogs;
// Now override their CreatedDate values using Test.setCreatedDate
DateTime today = System.now();
for (Integer i = 0; i < allLogs.size(); i++) {
// First 3 logs are 35 days old (should be deleted)
if (i < 3) {
Test.setCreatedDate(allLogs[i].Id, today.addDays(-35));
}
// Remaining 2 are recent (should not be deleted)
else {
Test.setCreatedDate(allLogs[i].Id, today.addDays(-5));
}
}
}
@isTest
static void testBatchDeletesOldLogs() {
// Optional: mock CheckAccessibility if you can
// CheckAccessibility.testIsDeletableOverride = true;
Test.startTest();
Database.executeBatch(new Batchtodeletelogs(), 200);
Test.stopTest();
}
@isTest
static void testBatchWithNoOldLogs() {
// Delete old logs first
delete [
SELECT Id FROM HIC_ShopifySync__shopify_log__c
WHERE CreatedDate <= :System.today().addDays(-30)
];
Test.startTest();
Database.executeBatch(new Batchtodeletelogs(), 200);
Test.stopTest();
}
@isTest
static void testBatchtodeletelogsExecute() {
// Create sample data
List<HIC_ShopifySync__shopify_log__c> logs = new List<HIC_ShopifySync__shopify_log__c>();
for (Integer i = 0; i < 5; i++) {
logs.add(new HIC_ShopifySync__shopify_log__c(Name = 'Log ' + i));
}
insert logs;
// Adjust CreatedDate values using Test.setCreatedDate
DateTime now = System.now();
for (Integer i = 0; i < logs.size(); i++) {
if (i < 3) {
// 3 old logs (to delete)
Test.setCreatedDate(logs[i].Id, now.addDays(-35));
} else {
// 2 recent logs (to keep)
Test.setCreatedDate(logs[i].Id, now.addDays(-5));
}
}
// Local stub for CheckAccessibility — ensures Database.delete() runs
// This version exists only inside the test context
// Run the batch
Test.startTest();
Database.executeBatch(new Batchtodeletelogs(), 200);
Test.stopTest();
}
}