Initial push
This commit is contained in:
112
appstore/validator_test.go
Normal file
112
appstore/validator_test.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package appstore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHandleError(t *testing.T) {
|
||||
var expected, actual error
|
||||
|
||||
// status 0
|
||||
expected = nil
|
||||
actual = HandleError(0)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status 21000
|
||||
expected = errors.New("The App Store could not read the JSON object you provided.")
|
||||
actual = HandleError(21000)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status 21002
|
||||
expected = errors.New("The data in the receipt-data property was malformed or missing.")
|
||||
actual = HandleError(21002)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status 21003
|
||||
expected = errors.New("The receipt could not be authenticated.")
|
||||
actual = HandleError(21003)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status 21005
|
||||
expected = errors.New("The receipt server is not currently available.")
|
||||
actual = HandleError(21005)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status 21007
|
||||
expected = errors.New("This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.")
|
||||
actual = HandleError(21007)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status 21008
|
||||
expected = errors.New("This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.")
|
||||
actual = HandleError(21008)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
|
||||
// status unkown
|
||||
expected = errors.New("An unknown error ocurred")
|
||||
actual = HandleError(100)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
expected := &Client{
|
||||
URL: "https://sandbox.itunes.apple.com/verifyReceipt",
|
||||
TimeOut: time.Second * 5,
|
||||
}
|
||||
|
||||
actual := New()
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewWithConfig(t *testing.T) {
|
||||
config := Config{
|
||||
IsProduction: true,
|
||||
TimeOut: time.Second * 2,
|
||||
}
|
||||
|
||||
expected := &Client{
|
||||
URL: "https://buy.itunes.apple.com/verifyReceipt",
|
||||
TimeOut: time.Second * 2,
|
||||
}
|
||||
|
||||
actual := NewWithConfig(config)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerify(t *testing.T) {
|
||||
client := New()
|
||||
|
||||
expected := IAPResponse{
|
||||
Status: 21002,
|
||||
}
|
||||
req := IAPRequest{
|
||||
ReceiptData: "dummy data",
|
||||
}
|
||||
actual, _ := client.Verify(&req)
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("got %v\nwant %v", actual, expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user