Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1501 api store #1623

Merged
merged 6 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions VkNet.Tests/Categories/Store/StoreCategoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using System;
using FluentAssertions;
using VkNet.Enums.StringEnums;
using VkNet.Tests.Infrastructure;
using Xunit;

namespace VkNet.Tests.Categories.Store;

public class StoreCategoryTest : CategoryBaseTest
{
protected override string Folder => "Store";

[Fact]
public void AddStickersToFavorite()
{
Url = "https://api.vk.com/method/store.addStickersToFavorite";

ReadCategoryJsonPath(nameof(AddStickersToFavorite));

var result = Api.Store.AddStickersToFavorite(new()
{
StickerIds = ["126", "70"]
});

result.Should()
.BeTrue();
}

[Fact]
public void GetFavoriteStickers()
{
Url = "https://api.vk.com/method/store.getFavoriteStickers";

ReadCategoryJsonPath(nameof(GetFavoriteStickers));

var result = Api.Store.GetFavoriteStickers();

result.Count.Should()
.Be(2);

var first = result[0];

first.Id.Should()
.Be(126);

first.InnerType.Should()
.Be("base_sticker_new");

first.IsAllowed.Should()
.BeTrue();

var second = result[1];

second.Id.Should()
.Be(70);

second.InnerType.Should()
.Be("base_sticker_new");

second.IsAllowed.Should()
.BeFalse();
}

[Fact]
public void GetProducts()
{
Url = "https://api.vk.com/method/store.getProducts";

ReadCategoryJsonPath(nameof(GetProducts));

var result = Api.Store.GetProducts(new()
{
Type = ProductType.Stickers,
ProductIds = ["148"],
Filters = [ProductStatusFilter.Purchased, ProductStatusFilter.Active],
Extended = true
});

result.Count.Should()
.Be(1);

var product = result[0];

product.Id.Should()
.Be(148);

product.Type.Should()
.Be(ProductType.Stickers);

product.IsNew.Should()
.BeFalse();

product.Copyright.Should()
.Be("ООО «ВКонтакте» 2017");

product.Purchased.Should()
.BeTrue();

product.Active.Should()
.BeTrue();

product.PurchaseDate.Should()
.Be(DateTime.Parse("2024-01-10 12:52:23 PM"));

product.Title.Should()
.Be("#ПушкинНашеВсё");

product.Stickers.Count.Should()
.Be(24);

product.Icon.BaseUrl.Should()
.Be("https://vk.com/sticker/packs/148/icon");

product.Previews.Count.Should()
.Be(5);
}

[Fact]
public void GetStickersKeywords()
{
Url = "https://api.vk.com/method/store.getStickersKeywords";

ReadCategoryJsonPath(nameof(GetStickersKeywords));

var result = Api.Store.GetStickersKeywords(new()
{
StickerIds = ["126"],
Aliases = true,
AllProducts = false,
NeedStickers = true
});

result.Dictionary.Count.Should()
.Be(1);

result.Dictionary[0].Words.Count.Should()
.Be(51);

result.Dictionary[0].UserStickers.Count.Should()
.Be(1);

var sticker = result.Dictionary[0].UserStickers[0];

sticker.InnerType.Should()
.Be("base_sticker_new");

sticker.Id.Should()
.Be(126);

sticker.IsAllowed.Should()
.BeTrue();
}

[Fact]
public void RemoveStickersFromFavorite()
{
Url = "https://api.vk.com/method/store.removeStickersFromFavorite";

ReadCategoryJsonPath(nameof(RemoveStickersFromFavorite));

var result = Api.Store.RemoveStickersFromFavorite(new()
{
StickerIds = ["126", "70"]
});

result.Should()
.BeTrue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": 1
}
17 changes: 17 additions & 0 deletions VkNet.Tests/TestData/Categories/Store/GetFavoriteStickers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"response": {
"count": 2,
"items": [
{
"inner_type": "base_sticker_new",
"sticker_id": 126,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 70,
"is_allowed": false
}
]
}
}
169 changes: 169 additions & 0 deletions VkNet.Tests/TestData/Categories/Store/GetProducts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"response": {
"count": 1,
"items": [
{
"id": 148,
"type": "stickers",
"is_new": false,
"copyright": "ООО «ВКонтакте» 2017",
"purchased": 1,
"active": 1,
"purchase_date": 1704891143,
"title": "#ПушкинНашеВсё",
"stickers": [
{
"inner_type": "base_sticker_new",
"sticker_id": 4639,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4640,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4641,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4642,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4643,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4644,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4645,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4646,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4647,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4648,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4649,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4650,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4651,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4652,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4653,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4654,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4655,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4656,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4657,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4658,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4659,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4660,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4661,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 4662,
"is_allowed": true
}
],
"icon": {
"base_url": "https://vk.com/sticker/packs/148/icon"
},
"previews": [
{
"url": "https://vk.com/sticker/2-148-thumb-22-",
"width": 22,
"height": 22
},
{
"url": "https://vk.com/sticker/2-148-thumb-34-",
"width": 34,
"height": 34
},
{
"url": "https://vk.com/sticker/2-148-thumb-44-",
"width": 44,
"height": 44
},
{
"url": "https://vk.com/sticker/2-148-thumb-68-",
"width": 68,
"height": 68
},
{
"url": "https://vk.com/sticker/2-148-thumb-102-",
"width": 102,
"height": 102
}
]
}
]
}
}
Loading
Loading