test
This commit is contained in:
parent
4398a442b4
commit
5b980e8ed1
@ -3588,6 +3588,82 @@ func TestListResourceShopItemsReturnsActiveSaleItems(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurchaseResourceShopItemUsesAuthenticatedUserAndCommandID(t *testing.T) {
|
||||
walletClient := &fakeWalletClient{
|
||||
purchaseShopResp: &walletv1.PurchaseResourceShopItemResponse{
|
||||
OrderId: "rshop_order_1",
|
||||
TransactionId: "wtx_shop_1",
|
||||
ResourceGrantId: "rgr_shop_1",
|
||||
CoinSpent: 300,
|
||||
Balance: &walletv1.AssetBalance{
|
||||
AssetType: "COIN",
|
||||
AvailableAmount: 700,
|
||||
Version: 2,
|
||||
},
|
||||
ShopItem: &walletv1.ResourceShopItem{
|
||||
ShopItemId: 9001,
|
||||
ResourceId: 7001,
|
||||
DurationDays: 3,
|
||||
PriceType: "coin",
|
||||
CoinPrice: 300,
|
||||
Resource: &walletv1.Resource{
|
||||
ResourceId: 7001,
|
||||
ResourceCode: "avatar_frame_gold",
|
||||
ResourceType: "avatar_frame",
|
||||
Name: "Gold Frame",
|
||||
},
|
||||
},
|
||||
Resource: &walletv1.UserResourceEntitlement{
|
||||
EntitlementId: "ent_shop_1",
|
||||
UserId: 42,
|
||||
ResourceId: 7001,
|
||||
Status: "active",
|
||||
Quantity: 1,
|
||||
Resource: &walletv1.Resource{
|
||||
ResourceId: 7001,
|
||||
ResourceCode: "avatar_frame_gold",
|
||||
ResourceType: "avatar_frame",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
handler := NewHandlerWithClients(&fakeRoomClient{}, nil, nil, &fakeUserProfileClient{})
|
||||
handler.SetWalletClient(walletClient)
|
||||
router := handler.Routes(auth.NewVerifier("secret"))
|
||||
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/resource-shop/items/9001/purchase", bytes.NewReader([]byte(`{"command_id":"cmd-shop-1"}`)))
|
||||
request.Header.Set("Authorization", "Bearer "+signGatewayToken(t, "secret", 42))
|
||||
recorder := httptest.NewRecorder()
|
||||
router.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("purchase shop status mismatch: got %d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
if walletClient.lastPurchaseShop == nil || walletClient.lastPurchaseShop.GetCommandId() != "cmd-shop-1" || walletClient.lastPurchaseShop.GetUserId() != 42 || walletClient.lastPurchaseShop.GetShopItemId() != 9001 {
|
||||
t.Fatalf("purchase shop request mismatch: %+v", walletClient.lastPurchaseShop)
|
||||
}
|
||||
var envelope struct {
|
||||
Code string `json:"code"`
|
||||
Data struct {
|
||||
OrderID string `json:"order_id"`
|
||||
TransactionID string `json:"transaction_id"`
|
||||
CoinSpent int64 `json:"coin_spent"`
|
||||
Balance struct {
|
||||
AvailableAmount int64 `json:"available_amount"`
|
||||
} `json:"balance"`
|
||||
Resource struct {
|
||||
EntitlementID string `json:"entitlement_id"`
|
||||
ResourceID int64 `json:"resource_id"`
|
||||
} `json:"resource"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.NewDecoder(recorder.Body).Decode(&envelope); err != nil {
|
||||
t.Fatalf("decode purchase shop failed: %v", err)
|
||||
}
|
||||
if envelope.Code != httpkit.CodeOK || envelope.Data.OrderID != "rshop_order_1" || envelope.Data.CoinSpent != 300 || envelope.Data.Balance.AvailableAmount != 700 || envelope.Data.Resource.EntitlementID != "ent_shop_1" {
|
||||
t.Fatalf("purchase shop envelope mismatch: %+v", envelope)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListGiftTabsReturnsActiveTypeConfigs(t *testing.T) {
|
||||
walletClient := &fakeWalletClient{
|
||||
listGiftConfigsResp: &walletv1.ListGiftConfigsResponse{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user