-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add snapshot test for avatar query (#525)
Co-authored-by: moreal <dev.moreal@gmail.com>
- Loading branch information
Showing
10 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,9 @@ public MailBox(IValue bencoded) | |
.Select(MailFactory.Create) | ||
.ToList(); | ||
} | ||
|
||
public MailBox() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Libplanet.Crypto; | ||
using Mimir.MongoDB.Bson; | ||
|
||
namespace Mimir.MongoDB.Repositories; | ||
|
||
public interface IAvatarRepository | ||
{ | ||
public Task<AvatarDocument> GetByAddressAsync(Address address); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...r.Tests/QueryTests/AvatarQueryTest.GraphQL_Query_Avatar_Returns_CorrectValue.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"data": { | ||
"avatar": { | ||
"address": "0x0000000000000000000000000000000000000000", | ||
"agentAddress": "0x0000000000000000000000000000000000000001", | ||
"blockIndex": 0, | ||
"characterId": 1, | ||
"name": "TestAvatar", | ||
"level": 0, | ||
"eventMap": [ | ||
{ | ||
"key": 1, | ||
"value": 1 | ||
} | ||
], | ||
"itemMap": [ | ||
{ | ||
"key": 1, | ||
"value": 1 | ||
} | ||
], | ||
"mailBox": { | ||
"mails": [ | ||
{ | ||
"blockIndex": 0, | ||
"id": "a9320f02-7794-4c3b-8071-701d501f9529", | ||
"requiredBlockIndex": 0, | ||
"typeId": "A" | ||
} | ||
] | ||
}, | ||
"monsterMap": [ | ||
{ | ||
"key": 1, | ||
"value": 1 | ||
} | ||
], | ||
"stageMap": [ | ||
{ | ||
"key": 1, | ||
"value": 1 | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using Lib9c.Models.Mails; | ||
using Lib9c.Models.States; | ||
using Libplanet.Crypto; | ||
using Mimir.MongoDB.Bson; | ||
using Mimir.MongoDB.Repositories; | ||
using Moq; | ||
using Nekoyume.Model; | ||
|
||
namespace Mimir.Tests.QueryTests; | ||
|
||
public class AvatarQueryTest | ||
{ | ||
[Fact] | ||
public async Task GraphQL_Query_Avatar_Returns_CorrectValue() | ||
{ | ||
var mockAddress = new Address("0x0000000000000000000000000000000000000000"); | ||
|
||
var stageMap = new CollectionMap(); | ||
var monsterMap = new CollectionMap(); | ||
var itemMap = new CollectionMap(); | ||
var eventMap = new CollectionMap(); | ||
Mail mail = new Mail() | ||
{ | ||
BlockIndex = 0, | ||
Id = Guid.Parse("a9320f02-7794-4c3b-8071-701d501f9529"), | ||
RequiredBlockIndex = 0, | ||
TypeId = "A" | ||
}; | ||
|
||
List<Mail> mails = new(); | ||
mails.Add(mail); | ||
MailBox mailBox = new MailBox() {Mails = mails}; | ||
|
||
stageMap.Add(1, 1); | ||
monsterMap.Add(1, 1); | ||
itemMap.Add(1, 1); | ||
eventMap.Add(1, 1); | ||
|
||
var avatar = new AvatarState | ||
{ | ||
Address = default, | ||
Version = 1, | ||
AgentAddress = new Address("0x0000000000000000000000000000000000000001"), | ||
MailBox = mailBox, | ||
BlockIndex = 0, | ||
DailyRewardReceivedIndex = 0, | ||
ActionPoint = 0, | ||
StageMap = stageMap, | ||
MonsterMap = monsterMap, | ||
ItemMap = itemMap, | ||
EventMap = eventMap, | ||
Hair = 0, | ||
Lens = 0, | ||
Ear = 0, | ||
Tail = 0, | ||
CombinationSlotAddresses = new List<Address>(){new Address()}, | ||
RankingMapAddress = default, | ||
Name = "TestAvatar", | ||
CharacterId = 1, | ||
Level = 0, | ||
Exp = 0, | ||
UpdatedAt = 0, | ||
|
||
|
||
|
||
// Add other mock data as needed | ||
}; | ||
|
||
var mockRepo = new Mock<IAvatarRepository>(); | ||
mockRepo | ||
.Setup(repo => repo.GetByAddressAsync(It.IsAny<Address>())) | ||
.ReturnsAsync(new AvatarDocument(0, new Address(), avatar)); | ||
|
||
var serviceProvider = TestServices.CreateServices(avatarRepositoryMock: mockRepo); | ||
|
||
var query = """ | ||
query { | ||
avatar(address: "0x0000000000000000000000000000000000000000") { | ||
address | ||
agentAddress | ||
blockIndex | ||
characterId | ||
name | ||
level | ||
eventMap { | ||
key | ||
value | ||
} | ||
itemMap { | ||
key | ||
value | ||
} | ||
mailBox { | ||
mails { | ||
blockIndex | ||
id | ||
requiredBlockIndex | ||
typeId | ||
} | ||
} | ||
monsterMap { | ||
key | ||
value | ||
} | ||
stageMap { | ||
key | ||
value | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetQuery(query)); | ||
|
||
await Verify(result); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters