Skip to content

Commit

Permalink
fix(test): e2e and scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Dec 13, 2018
1 parent b1021ef commit e64c81c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
21 changes: 11 additions & 10 deletions core/test/e2e_test.go
Expand Up @@ -179,13 +179,13 @@ func TestWithEnqueuer(t *testing.T) {
So(res.DisplayStatus, ShouldBeEmpty)
So(len(res.Devices), ShouldEqual, 0)

in, out, err := asyncEventsWithTimeout(alice.eventStream, 1)
in, out, err := asyncEventsWithTimeout(alice.eventStream, 2)
So(err, ShouldBeNil)
So(len(in), ShouldEqual, 0)
So(len(out), ShouldEqual, 1)
So(out[0].Kind, ShouldEqual, p2p.Kind_ContactRequest)
So(len(out), ShouldEqual, 2)
So(out[1].Kind, ShouldEqual, p2p.Kind_ContactRequest)

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{1, 0, 0, 0, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 0, 0, 0, 0, 0})

everythingWentFine()
})
Expand All @@ -211,6 +211,7 @@ func TestWithEnqueuer(t *testing.T) {
shouldIContinue(t)

envelope := <-alice.networkDriver.(*mock.Enqueuer).Queue()
envelope = <-alice.networkDriver.(*mock.Enqueuer).Queue()
event, err := alice.node.OpenEnvelope(alice.ctx, envelope)
So(err, ShouldBeNil)

Expand Down Expand Up @@ -704,11 +705,11 @@ func TestAliasesFlow(t *testing.T) {

conversations, err := bob.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 1)
So(len(conversations), ShouldEqual, 2)

conversations, err = alice.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 1)
So(len(conversations), ShouldEqual, 2)

everythingWentFine()
})
Expand Down Expand Up @@ -746,11 +747,11 @@ func TestAliasesFlow(t *testing.T) {

conversations, err := bob.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 2)
So(len(conversations), ShouldEqual, 3)

conversations, err = alice.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 2)
So(len(conversations), ShouldEqual, 3)

envelope = bob.networkDriver.(*mock.SimpleDriver).GetLastReceivedEnvelope()
So(envelope.Source, ShouldEqual, alias.AliasIdentifier)
Expand All @@ -777,11 +778,11 @@ func TestAliasesFlow(t *testing.T) {

conversations, err = bob.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 3)
So(len(conversations), ShouldEqual, 4)

conversations, err = alice.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 3)
So(len(conversations), ShouldEqual, 4)

envelope = bob.networkDriver.(*mock.SimpleDriver).GetLastReceivedEnvelope()
So(envelope.Source, ShouldNotEqual, alias.AliasIdentifier)
Expand Down
68 changes: 34 additions & 34 deletions core/test/scenario_test.go
Expand Up @@ -6,11 +6,10 @@ import (
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"

"berty.tech/core/api/node"
"berty.tech/core/api/p2p"
"berty.tech/core/entity"
. "github.com/smartystreets/goconvey/convey"
)

var cache = map[string]interface{}{}
Expand Down Expand Up @@ -61,6 +60,12 @@ func scenario(t *testing.T, alice, bob, eve *AppMock) {

everythingWentFine()
})
Convey("Alice has a new Conversation", FailureHalts, func() {
res, err := alice.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(res), ShouldEqual, 1)
cache["conversation_id"] = res[0].ID
})
Convey("Bob calls node.ContactAcceptRequest", FailureHalts, func() {
shouldIContinue(t)

Expand Down Expand Up @@ -122,21 +127,21 @@ func scenario(t *testing.T, alice, bob, eve *AppMock) {
})
Convey("Bob creates a conversation with Alice", FailureHalts, func() {

Convey("Bob has no conversation", FailureHalts, func() {
Convey("Bob has a conversation", FailureHalts, func() {
shouldIContinue(t)

conversations, err := bob.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 0)
So(len(conversations), ShouldEqual, 1)

everythingWentFine()
})
Convey("Alice has no conversation", FailureHalts, func() {
Convey("Alice has a conversation", FailureHalts, func() {
shouldIContinue(t)

conversations, err := alice.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 0)
So(len(conversations), ShouldEqual, 1)

everythingWentFine()
})
Expand All @@ -149,60 +154,55 @@ func scenario(t *testing.T, alice, bob, eve *AppMock) {

everythingWentFine()
})
Convey("Bob creates a conversation with Alice", FailureHalts, func() {
shouldIContinue(t)

res, err := bob.client.Node().ConversationCreate(internalCtx, &node.ConversationCreateInput{
Title: "Alice & Bob",
Topic: "hey!",
Contacts: []*entity.Contact{
{ID: alice.node.UserID()},
},
})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
cache["conversation_id"] = res.ID
time.Sleep(sleepBetweenSteps)

everythingWentFine()
})
Convey("Bob has a conversation with Alice", FailureHalts, func() {
Convey("Bob has a conversations with Alice", FailureHalts, func() {
shouldIContinue(t)

conversations, err := bob.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 1)

So(conversations[0].Title, ShouldEqual, "Alice & Bob")
So(conversations[0].Title, ShouldEqual, "")
So(len(conversations[0].Members), ShouldEqual, 2)
So(conversations[0].Members[0].ContactID, ShouldEqual, bob.node.UserID())
So(conversations[0].Members[1].ContactID, ShouldEqual, alice.node.UserID())
So(conversations[0].Members[0].Status, ShouldEqual, entity.ConversationMember_Owner)
So(conversations[0].Members[1].Status, ShouldEqual, entity.ConversationMember_Active)
memberBob := &entity.ConversationMember{}
memberAlice := &entity.ConversationMember{}
for _, member := range conversations[0].Members {
switch member.ContactID {
case alice.node.UserID():
memberAlice = member
case bob.node.UserID():
memberBob = member
}
}
So(memberBob.Contact.DisplayName, ShouldEqual, "Bob")
So(memberAlice.Contact.DisplayName, ShouldEqual, "Alice")
So(memberBob.ContactID, ShouldEqual, bob.node.UserID())
So(memberAlice.ContactID, ShouldEqual, alice.node.UserID())
So(memberBob.Status, ShouldEqual, entity.ConversationMember_Active)
So(memberAlice.Status, ShouldEqual, entity.ConversationMember_Owner)

everythingWentFine()
})
Convey("Alice has the conversation with Bob", FailureHalts, func() {
Convey("Alice has a conversation with Bob", FailureHalts, func() {
shouldIContinue(t)

conversations, err := alice.client.ConversationList(internalCtx, &node.ConversationListInput{})
So(err, ShouldBeNil)
So(len(conversations), ShouldEqual, 1)

So(conversations[0].Title, ShouldEqual, "Alice & Bob")
So(conversations[0].Title, ShouldEqual, "")
So(len(conversations[0].Members), ShouldEqual, 2)
So(conversations[0].Members[0].ContactID, ShouldNotEqual, conversations[0].Members[1].ContactID)
for _, member := range conversations[0].Members {
switch member.ContactID {
case alice.node.UserID():
So(member.Status, ShouldEqual, entity.ConversationMember_Active)
case bob.node.UserID():
So(member.Status, ShouldEqual, entity.ConversationMember_Owner)
case bob.node.UserID():
So(member.Status, ShouldEqual, entity.ConversationMember_Active)
}
}

everythingWentFine()
})

Convey("Eve has no conversation (again)", FailureHalts, func() {
shouldIContinue(t)

Expand Down

0 comments on commit e64c81c

Please sign in to comment.