Esempio n. 1
0
func TestMessageListSaved(t *testing.T) {
	runner, handler := getTestHandler()
	defer runner.Close()

	Convey("while testing message list save", t, func() {
		account := models.CreateAccountWithTest()
		channel := models.CreateChannelWithTest(account.Id)
		cm := models.CreateMessage(channel.Id, account.Id, models.ChannelMessage_TYPE_POST)

		Convey("messages can be saved", func() {
			cmls, err := cm.GetChannelMessageLists()
			So(err, ShouldBeNil)
			So(len(cmls), ShouldBeGreaterThan, 0)

			So(handler.MessageListSaved(&cmls[0]), ShouldBeNil)
			So(doBasicTestForMessage(handler, cmls[0].MessageId), ShouldBeNil)
		})

		Convey("messages can be cross-indexed", func() {
			c1 := models.CreateChannelWithTest(account.Id)
			_, err := c1.AddMessage(cm)
			So(err, ShouldBeNil)

			cmls, err := cm.GetChannelMessageLists()
			So(err, ShouldBeNil)
			So(len(cmls), ShouldEqual, 2)

			So(handler.MessageListSaved(&cmls[0]), ShouldBeNil)
			So(doBasicTestForMessage(handler, cmls[0].MessageId), ShouldBeNil)

			So(handler.MessageListSaved(&cmls[1]), ShouldBeNil)
			err = makeSureMessage(handler, cmls[1].MessageId, func(record map[string]interface{}, err error) bool {
				if err != nil {
					return false
				}

				if len((record["_tags"]).([]interface{})) != 2 {
					return false
				}

				return true
			})
			So(err, ShouldBeNil)
		})
	})
}
Esempio n. 2
0
func TestMailParse(t *testing.T) {
	r := runner.New("test")
	err := r.Init()
	if err != nil {
		panic(err)
	}

	defer r.Close()

	appConfig := config.MustRead(r.Conf.Path)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	Convey("while sending mail", t, func() {

		Convey("reponse should be success", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			c := socialapimodels.CreateChannelWithTest(acc.Id)
			socialapimodels.AddParticipantsWithTest(c.Id, acc.Id)

			cm := socialapimodels.CreateMessage(c.Id, acc.Id, socialapimodels.ChannelMessage_TYPE_POST)
			So(cm, ShouldNotBeNil)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			p := &models.Mail{
				From:              mongoUser.Email,
				OriginalRecipient: fmt.Sprintf("*****@*****.**", c.Id),
				MailboxHash:       fmt.Sprintf("messageid.%d", cm.Id),
				TextBody:          "Its an example of text message",
				StrippedTextReply: "This one is reply message",
			}

			res, err := rest.MailParse(p)
			So(err, ShouldBeNil)
			So(res, ShouldNotBeNil)
		})
	})
}
Esempio n. 3
0
func TestMessageUpdated(t *testing.T) {
	runner, handler := getTestHandler()
	defer runner.Close()

	Convey("messages can be updated", t, func() {
		account := models.CreateAccountWithTest()
		channel := models.CreateChannelWithTest(account.Id)
		cm := models.CreateMessage(channel.Id, account.Id, models.ChannelMessage_TYPE_POST)

		cmls, err := cm.GetChannelMessageLists()
		So(err, ShouldBeNil)
		So(len(cmls), ShouldBeGreaterThan, 0)

		So(handler.MessageListSaved(&cmls[0]), ShouldBeNil)
		err = makeSureMessage(handler, cmls[0].MessageId, func(record map[string]interface{}, err error) bool {
			if err != nil {
				return false
			}

			return true
		})
		So(err, ShouldBeNil)

		cm.Body = "updated body"

		So(cm.Update(), ShouldBeNil)
		So(handler.MessageUpdated(cm), ShouldBeNil)
		err = makeSureMessage(handler, cmls[0].MessageId, func(record map[string]interface{}, err error) bool {
			if err != nil {
				return false
			}

			if record["body"].(string) != "updated body" {
				return false
			}

			return true
		})
		So(err, ShouldBeNil)
	})
}
Esempio n. 4
0
func TestPersist(t *testing.T) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

	// init mongo connection
	appConfig := config.MustRead(r.Conf.Path)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	Convey("while testing Persist", t, func() {

		Convey("testing post message while all is well", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			c := socialapimodels.CreateChannelWithTest(acc.Id)

			//cm := socialapimodels.CreateMessage(c.Id, acc.Id)
			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			m := &Mail{
				From:              mongoUser.Email,
				OriginalRecipient: fmt.Sprintf("*****@*****.**", c.Id),
				MailboxHash:       fmt.Sprintf("channelid.%d", c.Id),
				TextBody:          "Its an example of text message",
			}

			err = m.Persist()
			So(err, ShouldBeNil)
		})

		Convey("reply should have messageid", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			c := socialapimodels.CreateChannelWithTest(acc.Id)
			socialapimodels.AddParticipantsWithTest(c.Id, acc.Id)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			m := &Mail{
				From:              mongoUser.Email,
				OriginalRecipient: fmt.Sprintf("*****@*****.**", c.Id),
				MailboxHash:       fmt.Sprintf("channelid.%d", c.Id),
				TextBody:          "Its an example of text message",
			}

			err = m.Persist()
			So(err, ShouldEqual, bongo.RecordNotFound)
		})

		Convey("testing reply message if all is well", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			c := socialapimodels.CreateChannelWithTest(acc.Id)
			socialapimodels.AddParticipantsWithTest(c.Id, acc.Id)

			cm := socialapimodels.CreateMessage(c.Id, acc.Id, socialapimodels.ChannelMessage_TYPE_POST)
			So(cm, ShouldNotBeNil)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			m := &Mail{
				From:              mongoUser.Email,
				OriginalRecipient: fmt.Sprintf("*****@*****.**", c.Id),
				MailboxHash:       fmt.Sprintf("messageid.%d", cm.Id),
				TextBody:          "Its an example of text message",
				StrippedTextReply: "This one is reply message",
			}

			err = m.Persist()
			So(err, ShouldBeNil)
		})

		Convey("testing reply message, record not found if user is not a participant", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			c := socialapimodels.CreateChannelWithTest(acc.Id)

			cm := socialapimodels.CreateMessage(c.Id, acc.Id, socialapimodels.ChannelMessage_TYPE_POST)
			So(cm, ShouldNotBeNil)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			m := &Mail{
				From:              mongoUser.Email,
				OriginalRecipient: fmt.Sprintf("*****@*****.**", c.Id),
				MailboxHash:       fmt.Sprintf("messageid.%d", cm.Id),
				TextBody:          "Its an example of text message",
				StrippedTextReply: "This one is reply message",
			}

			err = m.persistPost(acc.Id)
			So(err, ShouldNotBeNil)
		})
	})
}