73 lines
12 KiB
OpenEdge ABL
73 lines
12 KiB
OpenEdge ABL
@isTest
|
|
public with sharing class UpdateCheckoutFromShopify_Test {
|
|
@isTest static void TestRestPostMethod(){
|
|
|
|
|
|
// CustomSettingRecordInsert.InsertingFieldMapping();
|
|
CustomSettingRecordInsert.InsertingConfiguration();
|
|
CustomSettingRecordInsert.InsertingWebhook();
|
|
HIC_ShopifySync__HIC_Field_Mapping__c sf1 = new HIC_ShopifySync__HIC_Field_Mapping__c();
|
|
sf1.HIC_ShopifySync__IsSFID__c = false;
|
|
sf1.HIC_ShopifySync__Object_Name__c = 'HIC_ShopifySync__Checkout__c';
|
|
sf1.name = 'HIC_ShopifySync__Checkout__c-Currency__c';
|
|
sf1.HIC_ShopifySync__SF_Field__c = 'HIC_ShopifySync__Currency__c';
|
|
sf1.HIC_ShopifySync__Shopify_Fields__c = 'Currency';
|
|
sf1.HIC_ShopifySync__Store__c = 'demoorg10satyam';
|
|
|
|
insert sf1;
|
|
|
|
HIC_ShopifySync__HIC_Field_Mapping__c sf2 = new HIC_ShopifySync__HIC_Field_Mapping__c();
|
|
sf2.HIC_ShopifySync__IsSFID__c = false;
|
|
sf2.HIC_ShopifySync__Object_Name__c = 'HIC_ShopifySync__Checkout_LineItem__c';
|
|
sf2.name = 'HIC_ShopifySync__Checkout_LineItem__c-HIC_ShopifySync__Price__c';
|
|
sf2.HIC_ShopifySync__SF_Field__c = 'HIC_ShopifySync__Price__c';
|
|
sf2.HIC_ShopifySync__Shopify_Fields__c = 'price';
|
|
sf2.HIC_ShopifySync__Store__c = 'demoorg10satyam';
|
|
|
|
insert sf2;
|
|
|
|
List<HIC_ShopifySync__HIC_Configuration__c> configuration = New List<HIC_ShopifySync__HIC_Configuration__c>();
|
|
HIC_ShopifySync__HIC_Configuration__c shopifyConfiguration = New HIC_ShopifySync__HIC_Configuration__c();
|
|
shopifyConfiguration.Name = 'Default';
|
|
shopifyConfiguration.HIC_ShopifySync__Account_Contact__c = true;
|
|
shopifyConfiguration.HIC_ShopifySync__Person_Account__c = false;
|
|
shopifyConfiguration.HIC_ShopifySync__Default_Account__c = false;
|
|
shopifyConfiguration.HIC_ShopifySync__Shopify_URL__c = 'https://demoorg10satyam.myshopify.com';
|
|
shopifyConfiguration.HIC_ShopifySync__API_Key__c = 'test';
|
|
shopifyConfiguration.HIC_ShopifySync__Private_Key_Password__c = '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';
|
|
shopifyConfiguration.HIC_ShopifySync__Store__c = 'demoorg10satyam';
|
|
configuration.add(shopifyConfiguration);
|
|
insert configuration;
|
|
|
|
Restrequest req = new Restrequest();
|
|
req.requestbody = Blob.valueOf('{"buyer_accepts_marketing":false,"cart_token":"db6fad21d337afce5a65831662cf44bf","closed_at":null,"completed_at":null,"created_at":"2023-04-27T09:15:41-04:00","currency":"INR","presentment_currency":"INR","customer_locale":"en-IN","device_id":null,"email":null,"gateway":null,"id":36668717957399,"landing_site":"/password","location_id":null,"note":null,"note_attributes":[],"phone":"+917048948110","referring_site":"","source_identifier":null,"source_url":null,"taxes_included":false,"token":"f608708ffd25236f7e3a55623158c0ec","total_weight":0,"updated_at":"2023-04-27T09:15:41-04:00","user_id":null,"customer":{"id":6900902297879,"email":null,"accepts_marketing":false,"created_at":"2023-04-27T09:15:41-04:00","updated_at":"2023-04-27T09:15:41-04:00","first_name":"Satyam","last_name":"Mishra","orders_count":0,"state":"disabled","total_spent":"0.00","last_order_id":null,"note":null,"verified_email":true,"multipass_identifier":null,"tax_exempt":false,"tags":"","last_order_name":null,"currency":"INR","phone":"+917048948110","accepts_marketing_updated_at":"2023-04-27T09:15:41-04:00","marketing_opt_in_level":null,"tax_exemptions":[],"email_marketing_consent":null,"sms_marketing_consent":{"state":"not_subscribed","opt_in_level":"single_opt_in","consent_updated_at":null,"consent_collected_from":"SHOPIFY"},"admin_graphql_api_id":"gid://shopify/Customer/6900902297879","default_address":{"id":9148733325591,"customer_id":6900902297879,"first_name":"Satyam","last_name":"Mishra","company":null,"address1":"street noida 68","address2":"Pegasus one","city":"Noida","province":"Uttar Pradesh","country":"India","zip":"201308","phone":null,"name":"Satyam Mishra","province_code":"UP","country_code":"IN","country_name":"India","default":true}},"source":null,"source_name":"web","name":"#36668717957399","discount_codes":[],"total_discounts":"0.00","total_line_items_price":"100.00","total_price":"118.00","total_tax":"18.00","subtotal_price":"100.00","total_duties":null,"abandoned_checkout_url":"https://demoorg10satyam.myshopify.com/74610213143/checkouts/ac/db6fad21d337afce5a65831662cf44bf/recover?key=6518c7ed0ee9cf500c429f4006633024","shipping_lines":[{"code":"Standard","price":"0.00","source":"shopify","title":"Standard","presentment_title":"Standard","validation_context":null,"phone":null,"markup":"0.00","carrier_identifier":null,"carrier_service_id":null,"api_client_id":580111,"delivery_option_group":{"token":"9b5edb8a4c172b33fbb617dd46ab0281","type":"one_time_purchase"},"delivery_expectation_range":null,"delivery_expectation_type":null,"tax_lines":[]}],"tax_lines":[{"position":1,"price":"18.00","rate":0.18,"title":"IGST","source":null,"compare_at":"18.00","zone":null,"channel_liable":false,"identifier":null}],"shipping_address":{"first_name":"Satyam","address1":"street noida 68","phone":null,"city":"Noida","zip":"201308","province":"UP","country":"IN","last_name":"Mishra","address2":"Pegasus one","company":null,"latitude":null,"longitude":null,"name":"Satyam Mishra","country_code":"IN","province_code":"UP"},"billing_address":{"first_name":"Satyam","address1":"street noida 68","phone":null,"city":"Noida","zip":"201308","province":"UP","country":"IN","last_name":"Mishra","address2":"Pegasus one","company":null,"latitude":null,"longitude":null,"name":"Satyam Mishra","country_code":"IN","province_code":"UP"},"line_items":[{"key":null,"destination_location_id":null,"fulfillment_service":"manual","gift_card":false,"grams":0,"origin_location_id":null,"presentment_title":"Cap","presentment_variant_title":"Default Title","product_id":8251589230871,"properties":[],"quantity":1,"requires_shipping":true,"sku":"10","taxable":true,"title":"Cap","variant_id":44935361200407,"variant_title":null,"variant_price":"100.00","vendor":"demoorg10satyam","unit_price_measurement":{"measured_type":"","quantity_value":0,"quantity_unit":"","reference_value":0,"reference_unit":""},"rank":null,"line_price":"100.00","price":"100.00","applied_discounts":[],"tax_lines":[{"position":0,"price":"18.00","rate":0.18,"title":"IGST","source":null,"compare_at":"18.00","zone":null,"channel_liable":false,"identifier":null}]}]}');
|
|
Restresponse res = new Restresponse();
|
|
req.requestURI = 'https://page-app-7336-dev-ed.develop.my.salesforce.com/services/apexrest/UpdateCheckoutFromShopify';
|
|
req.httpMethod = 'POST';
|
|
//Map <String, String> params = new Map <String, String>();
|
|
//params.put('store', 'demoorg10satyam')
|
|
req.params.put('store', 'demoorg10satyam');
|
|
RestContext.request = req;
|
|
RestContext.response= res;
|
|
res.statusCode = 200;
|
|
|
|
// For Authetication First Via Admin
|
|
RestRequest authenticationReq = new RestRequest();
|
|
RestResponse authenticationRes = new RestResponse();
|
|
authenticationReq.requestbody = Blob.valueOf('{"buyer_accepts_marketing":false,"cart_token":"db6fad21d337afce5a65831662cf44bf","closed_at":null,"completed_at":null,"created_at":"2023-04-27T09:15:41-04:00","currency":"INR","presentment_currency":"INR","customer_locale":"en-IN","device_id":null,"email":null,"gateway":null,"id":36668717957399,"landing_site":"/password","location_id":null,"note":null,"note_attributes":[],"phone":"+917048948110","referring_site":"","source_identifier":null,"source_url":null,"taxes_included":false,"token":"f608708ffd25236f7e3a55623158c0ec","total_weight":0,"updated_at":"2023-04-27T09:15:41-04:00","user_id":null,"customer":{"id":6900902297879,"email":null,"accepts_marketing":false,"created_at":"2023-04-27T09:15:41-04:00","updated_at":"2023-04-27T09:15:41-04:00","first_name":"Satyam","last_name":"Mishra","orders_count":0,"state":"disabled","total_spent":"0.00","last_order_id":null,"note":null,"verified_email":true,"multipass_identifier":null,"tax_exempt":false,"tags":"","last_order_name":null,"currency":"INR","phone":"+917048948110","accepts_marketing_updated_at":"2023-04-27T09:15:41-04:00","marketing_opt_in_level":null,"tax_exemptions":[],"email_marketing_consent":null,"sms_marketing_consent":{"state":"not_subscribed","opt_in_level":"single_opt_in","consent_updated_at":null,"consent_collected_from":"SHOPIFY"},"admin_graphql_api_id":"gid://shopify/Customer/6900902297879","default_address":{"id":9148733325591,"customer_id":6900902297879,"first_name":"Satyam","last_name":"Mishra","company":null,"address1":"street noida 68","address2":"Pegasus one","city":"Noida","province":"Uttar Pradesh","country":"India","zip":"201308","phone":null,"name":"Satyam Mishra","province_code":"UP","country_code":"IN","country_name":"India","default":true}},"source":null,"source_name":"web","name":"#36668717957399","discount_codes":[],"total_discounts":"0.00","total_line_items_price":"100.00","total_price":"118.00","total_tax":"18.00","subtotal_price":"100.00","total_duties":null,"abandoned_checkout_url":"https://demoorg10satyam.myshopify.com/74610213143/checkouts/ac/db6fad21d337afce5a65831662cf44bf/recover?key=6518c7ed0ee9cf500c429f4006633024","shipping_lines":[{"code":"Standard","price":"0.00","source":"shopify","title":"Standard","presentment_title":"Standard","validation_context":null,"phone":null,"markup":"0.00","carrier_identifier":null,"carrier_service_id":null,"api_client_id":580111,"delivery_option_group":{"token":"9b5edb8a4c172b33fbb617dd46ab0281","type":"one_time_purchase"},"delivery_expectation_range":null,"delivery_expectation_type":null,"tax_lines":[]}],"tax_lines":[{"position":1,"price":"18.00","rate":0.18,"title":"IGST","source":null,"compare_at":"18.00","zone":null,"channel_liable":false,"identifier":null}],"shipping_address":{"first_name":"Satyam","address1":"street noida 68","phone":null,"city":"Noida","zip":"201308","province":"UP","country":"IN","last_name":"Mishra","address2":"Pegasus one","company":null,"latitude":null,"longitude":null,"name":"Satyam Mishra","country_code":"IN","province_code":"UP"},"billing_address":{"first_name":"Satyam","address1":"street noida 68","phone":null,"city":"Noida","zip":"201308","province":"UP","country":"IN","last_name":"Mishra","address2":"Pegasus one","company":null,"latitude":null,"longitude":null,"name":"Satyam Mishra","country_code":"IN","province_code":"UP"},"line_items":[{"key":null,"destination_location_id":null,"fulfillment_service":"manual","gift_card":false,"grams":0,"origin_location_id":null,"presentment_title":"Cap","presentment_variant_title":"Default Title","product_id":8251589230871,"properties":[],"quantity":1,"requires_shipping":true,"sku":"10","taxable":true,"title":"Cap","variant_id":44935361200407,"variant_title":null,"variant_price":"100.00","vendor":"demoorg10satyam","unit_price_measurement":{"measured_type":"","quantity_value":0,"quantity_unit":"","reference_value":0,"reference_unit":""},"rank":null,"line_price":"100.00","price":"100.00","applied_discounts":[],"tax_lines":[{"position":0,"price":"18.00","rate":0.18,"title":"IGST","source":null,"compare_at":"18.00","zone":null,"channel_liable":false,"identifier":null}]}]}');
|
|
authenticationReq.params.put('store', 'demoorg10satyam');
|
|
authenticationReq.requestURI = 'https://page-app-7336-dev-ed.develop.my.salesforce.com/services/apexrest/UpdateCheckoutFromShopify'; //Request URL
|
|
authenticationReq.httpMethod = 'POST';
|
|
|
|
RestContext.request = authenticationReq;
|
|
RestContext.response= authenticationRes;
|
|
authenticationRes.statusCode = 200;
|
|
|
|
Test.startTest();
|
|
UpdateCheckoutsFromShopify.UpdateCheckoutsFromShopify() ;
|
|
|
|
Test.stopTest();
|
|
system.assertequals(200, res.statuscode);
|
|
system.assertequals(200, authenticationRes.statuscode);
|
|
}
|
|
} |