75 lines
2.7 KiB
OpenEdge ABL
75 lines
2.7 KiB
OpenEdge ABL
@IsTest
|
|
public class UpdateAccessToken_Test {
|
|
@IsTest
|
|
static void testUpdateToken() {
|
|
|
|
|
|
String requestBodyJSON = '{"access_token": "sample_access_token"}';
|
|
|
|
List<HIC_ShopifySync__HIC_Configuration__c> ConList = new List<HIC_ShopifySync__HIC_Configuration__c>();
|
|
HIC_ShopifySync__HIC_Configuration__c con = new HIC_ShopifySync__HIC_Configuration__c();
|
|
con.name = 'Default';
|
|
con.HIC_ShopifySync__Private_Key_Password__c = '0000000000000000True';
|
|
con.HIC_ShopifySync__Opportunity__c = True;
|
|
con.HIC_ShopifySync__Order__c = true;
|
|
con.HIC_ShopifySync__Opportunity_Line_Item__c = True;
|
|
con.HIC_ShopifySync__Order_Line_Item__c = True;
|
|
con.HIC_ShopifySync__Person_Account__c = false;
|
|
con.HIC_ShopifySync__Store__c = '123';
|
|
ConList.add(con);
|
|
insert ConList;
|
|
|
|
|
|
RestRequest request = new RestRequest();
|
|
request.requestURI = '/services/apexrest/UpdateAccessToken/';
|
|
request.httpMethod = 'POST';
|
|
request.requestBody = Blob.valueOf(requestBodyJSON);
|
|
|
|
|
|
RestResponse response = new RestResponse();
|
|
RestContext.request = request;
|
|
RestContext.response = response;
|
|
|
|
|
|
|
|
|
|
Test.startTest();
|
|
UpdateAccessToken.updatetoken();
|
|
UpdateAccessToken.updatetoken();
|
|
Test.stopTest();
|
|
|
|
}
|
|
|
|
@IsTest
|
|
static void testUpdateAccessTokenBlock() {
|
|
HIC_ShopifySync__Configuration__c config = new HIC_ShopifySync__Configuration__c(
|
|
Name = 'Default',
|
|
HIC_ShopifySync__API_Key__c = 'dummyKey',
|
|
HIC_ShopifySync__Private_Key_Password__c = 'dummySecret',
|
|
HIC_ShopifySync__Shopify_URL__c = 'https://test.myshopify.com'
|
|
);
|
|
insert config;
|
|
|
|
RestRequest req = new RestRequest();
|
|
RestResponse res = new RestResponse();
|
|
|
|
req.requestBody = Blob.valueOf('{"access_token":"abc123"}');
|
|
req.httpMethod = 'POST';
|
|
req.requestURI = '/services/apexrest/UpdateAccessToken/';
|
|
RestContext.request = req;
|
|
RestContext.response = res;
|
|
|
|
Test.startTest();
|
|
UpdateAccessToken.updatetoken();
|
|
Test.stopTest();
|
|
|
|
HIC_ShopifySync__Configuration__c updatedConfig = [
|
|
SELECT HIC_ShopifySync__Access_Token__c
|
|
FROM HIC_ShopifySync__Configuration__c
|
|
WHERE Id = :config.Id
|
|
];
|
|
System.assertNotEquals(null, updatedConfig.HIC_ShopifySync__Access_Token__c, 'Access token should be set');
|
|
//System.assertEquals('{"access_token":"abc123"}', updatedConfig.HIC_ShopifySync__Access_Token__c, 'Access token should match request body');
|
|
}
|
|
|
|
} |