package appChargeUtil

import (
	"fmt"
	"testing"
)

func TestValidateCharge(t *testing.T) {
	bundleIdentifierList := make([]string, 0, 4)
	productId := ""

	receiptObj, isValid, _ := ValidateCharge(bundleIdentifierList, productId, "[encoded data, 4436 characters]", false)
	fmt.Printf("1. receiptObj:%s, isValid:%t\n", receiptObj, isValid)
	if isValid != false {
		t.Errorf("it should be invalid, but now valid\n")
		return
	}

	productId = "xh_6"
	receiptObj, isValid, _ = ValidateCharge(bundleIdentifierList, productId, "[encoded data, 4436 characters]", false)
	fmt.Printf("2. receiptObj:%s, isValid:%t\n", receiptObj, isValid)
	if isValid != false {
		t.Errorf("it should be invalid, but now valid\n")
		return
	}

	bundleIdentifierList = append(bundleIdentifierList, "com.mqkk.game.xhs")
	receiptObj, isValid, _ = ValidateCharge(bundleIdentifierList, productId, "[encoded data, 4436 characters]", false)
	fmt.Printf("3. receiptObj:%s, isValid:%t\n", receiptObj, isValid)
	if isValid != false {
		t.Errorf("it should be invalid, but now valid\n")
		return
	}

	bundleIdentifierList = append(bundleIdentifierList, "com.yh.game.xhs")
	receiptObj, isValid, _ = ValidateCharge(bundleIdentifierList, productId, "[encoded data, 4436 characters]", false)
	fmt.Printf("4. receiptObj:%s, isValid:%t\n", receiptObj, isValid)
	if isValid != true {
		t.Errorf("it should be valid, but now invalid\n")
		return
	}

	bundleIdentifierList = append(bundleIdentifierList, "com.yh.game.xhs")
	receiptObj, isValid, _ = ValidateCharge(bundleIdentifierList, productId, "[encoded data, 4436 characters]", true)
	fmt.Printf("5. receiptObj:%s, isValid:%t\n", receiptObj, isValid)
	if isValid == false {
		receiptObj, isValid, _ = ValidateCharge(bundleIdentifierList, productId, "[encoded data, 4436 characters]", false)
		fmt.Printf("6. receiptObj:%s, isValid:%t\n", receiptObj, isValid)
		if isValid != true {
			t.Errorf("it should be valid, but now invalid\n")
			return
		}
	} else {
		t.Errorf("it should be invalid, but now valid\n")
		return
	}
}
