Пример #1
0
func TestAccountParticipantAdded(t *testing.T) {
	runner, handler := getTestHandler()
	defer runner.Close()

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

	Convey("given some account", t, func() {
		acc, err := models.CreateAccountInBothDbs()
		So(err, ShouldBeNil)
		So(acc, ShouldNotBeNil)

		tc1 := models.CreateTypedGroupedChannelWithTest(
			acc.Id,
			models.Channel_TYPE_TOPIC,
			models.Channel_KODING_NAME,
		)

		models.AddParticipantsWithTest(tc1.Id, acc.Id)

		cp := &models.ChannelParticipant{
			ChannelId:      tc1.Id,
			AccountId:      acc.Id,
			StatusConstant: models.ChannelParticipant_STATUS_ACTIVE,
		}

		Convey("when the account is already on algolia", func() {
			err := handler.AccountCreated(acc)
			So(err, ShouldBeNil)
			So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)

			err = handler.ParticipantCreated(cp)
			So(err, ShouldBeNil)

			So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)
			So(makeSureHasTag(handler, acc.OldId, strconv.FormatInt(tc1.Id, 10)), ShouldBeNil)

			Convey("trying to add again should success", func() {
				err = handler.ParticipantCreated(cp)
				So(err, ShouldBeNil)

				So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)
				So(makeSureHasTag(handler, acc.OldId, strconv.FormatInt(tc1.Id, 10)), ShouldBeNil)
				So(makeSureTagLen(handler, acc.OldId, 2), ShouldBeNil)
			})
		})

		Convey("when the account is not on algolia", func() {
			err = handler.ParticipantCreated(cp)
			So(err, ShouldBeNil)

			So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)
			So(makeSureHasTag(handler, acc.OldId, strconv.FormatInt(tc1.Id, 10)), ShouldBeNil)
			So(makeSureTagLen(handler, acc.OldId, 1), ShouldBeNil)
		})
	})
}
Пример #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)
		})
	})
}
Пример #3
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)
		})
	})
}