@isTest(SeeAllData = false)
public with sharing class NFM211RestTest {

    /* 目前只是作为接数据用，且数据中没有关联其他表字段 故直接捏造接口日志
     *  未来如果增加逻辑，需要对应修改。
    */

    /* 测试促销政策 正常+必填验证 */
    static testMethod void testNFM211_01() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210525';
        iflog.Type__c ='NFM211' ;
        iflog.Log__c = '[{"SpoID":"SR052501","PromotionNo":"052501","Description":"测试01","Memo":"测试01","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":null,"IsCheckProductCount":false,"Price":null,"ProductType":"","ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3},{"Model":"CF-H260AI","Quantity":1}]},{"SpoID":"SR052502","PromotionNo":"052502","Description":"测试02","Memo":"测试02","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":null,"Price":120.0,"ProductType":"测试02","ifNecessary":false,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052503","PromotionNo":"052503","Description":"测试03","Memo":"测试03","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":null,"ProductType":"测试03","ifNecessary":false,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052504","PromotionNo":"052504","Description":"测试04","Memo":"测试04","Category":"促销政策","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试04","ifNecessary":false,"OrderNo":0,"ApplyStatus":"作废","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]}]';
        iflog.RowDataFlg__c = true;

        insert iflog;
        System.Test.startTest();
        NFM211Rest.executefuture(iflog.id);
        System.Test.stopTest();

    }
    /* 测试一般产品 正常 + 必填验证*/
    static testMethod void testNFM211_02() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210525';
        iflog.Type__c ='NFM211' ;
        iflog.Log__c = '[{"SpoID":"SR052501","PromotionNo":"052501","Description":"测试01","Memo":"测试01","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":null,"IsCheckProductCount":null,"Price":null,"ProductType":null,"ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3},{"Model":"CF-H260AI","Quantity":1}]},{"SpoID":"SR052502","PromotionNo":"052502","Description":"测试02","Memo":"测试02","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试02","ifNecessary":null,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052503","PromotionNo":"052503","Description":"测试03","Memo":"测试03","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试03","ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052504","PromotionNo":"052504","Description":"测试04","Memo":"测试04","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试04","ifNecessary":false,"OrderNo":0,"ApplyStatus":"作废","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]}]';
        iflog.RowDataFlg__c = true;

        insert iflog;
        System.Test.startTest();
        NFM211Rest.executefuture(iflog.id);
        System.Test.stopTest();

    }
    /* 测试报错 */
    static testMethod void testNFM211_03() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210525';
        iflog.Type__c ='NFM211' ;
        iflog.Log__c = '[{"SpoID":"SR052501","PromotionNo":"052501","Description":"测试01","Memo":"测试01","Category":"促销价格产品","DateFrom":"测试01","DateTo":"测试01","IfContainsGuarantee":null,"IsCheckProductCount":null,"Price":null,"ProductType":null,"ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3},{"Model":"CF-H260AI","Quantity":1}]},{"SpoID":"SR052502","PromotionNo":"052502","Description":"测试02","Memo":"测试02","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试02","ifNecessary":null,"OrderNo":0,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052503","PromotionNo":"052503","Description":"测试03","Memo":"测试03","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试03","ifNecessary":false,"OrderNo":null,"ApplyStatus":"完成","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]},{"SpoID":"SR052504","PromotionNo":"052504","Description":"测试04","Memo":"测试04","Category":"促销价格产品","DateFrom":"20210101","DateTo":"20211010","IfContainsGuarantee":false,"IsCheckProductCount":false,"Price":120.0,"ProductType":"测试04","ifNecessary":false,"OrderNo":0,"ApplyStatus":"作废","PromotionProduct_Info":[{"Model":"AR-T12E","Quantity":3}]}]';
        iflog.RowDataFlg__c = true;

        insert iflog;
        System.Test.startTest();
        NFM211Rest.executefuture(iflog.id);
        System.Test.stopTest();

    }
    /* 测试调用execute方法 */
    @isTest static void test_method_execute() {

        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        String JsonMsg = '{"Monitoring":{"Tag":"MSGH","Sender":"SPO","Receiver":"SFDC","MessageType":"NFM211","MessageGroupNumber":"20210000004695","NumberOfRecord":"4","TransmissionDateTime":"2021-06-23","Text":""},"Header":[{"SpoID":"94","PromotionNo":"202","Description":"2019年9月5日 测试","Memo":"测试","Category":"1","DateFrom":"20190912","DateTo":"20221016","IfContainsGuarantee":true,"IsCheckProductCount":true,"Price":12.0,"ProductType":"","ifNecessary":false,"OrderNo":0,"ApplyStatus":"同意","Items":[{"Model":"01","Quantity":2}]}]}';
        req.requestURI = 'services/apexrest/NFM211/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM211Rest.execute();

        Test.stopTest();
    }
}