Exemplo n.º 1
0
func withStubData(endpoint string, f func(username string, groupName string, sessionID string)) {
	acc, _, groupName := models.CreateRandomGroupDataWithChecks()

	group, err := modelhelper.GetGroup(groupName)
	tests.ResultedWithNoErrorCheck(group, err)

	err = modelhelper.MakeAdmin(bson.ObjectIdHex(acc.OldId), group.Id)
	So(err, ShouldBeNil)

	ses, err := modelhelper.FetchOrCreateSession(acc.Nick, groupName)
	tests.ResultedWithNoErrorCheck(ses, err)

	f(acc.Nick, groupName, ses.ClientId)
}
Exemplo n.º 2
0
func withStubData(f func(username string, groupName string, sessionID string)) {
	acc, _, groupName := models.CreateRandomGroupDataWithChecks()
	group, err := modelhelper.GetGroup(groupName)
	tests.ResultedWithNoErrorCheck(group, err)

	err = modelhelper.MakeAdmin(bson.ObjectIdHex(acc.OldId), group.Id)
	So(err, ShouldBeNil)

	ses, err := modelhelper.FetchOrCreateSession(acc.Nick, groupName)
	tests.ResultedWithNoErrorCheck(ses, err)

	cus, err := EnsureCustomerForGroup(acc.Nick, groupName, &stripe.CustomerParams{})
	tests.ResultedWithNoErrorCheck(cus, err)

	f(acc.Nick, groupName, ses.ClientId)

	err = DeleteCustomerForGroup(groupName)
	So(err, ShouldBeNil)
}
Exemplo n.º 3
0
func withStubData(endpoint string, f func(username string, groupName string, sessionID string)) {
	createURL := endpoint + EndpointCustomerCreate
	acc, _, groupName := models.CreateRandomGroupDataWithChecks()

	group, err := modelhelper.GetGroup(groupName)
	tests.ResultedWithNoErrorCheck(group, err)

	err = modelhelper.MakeAdmin(bson.ObjectIdHex(acc.OldId), group.Id)
	So(err, ShouldBeNil)

	ses, err := modelhelper.FetchOrCreateSession(acc.Nick, groupName)
	tests.ResultedWithNoErrorCheck(ses, err)

	req, err := json.Marshal(&stripe.CustomerParams{})
	tests.ResultedWithNoErrorCheck(req, err)

	res, err := rest.DoRequestWithAuth("POST", createURL, req, ses.ClientId)
	tests.ResultedWithNoErrorCheck(res, err)

	f(acc.Nick, groupName, ses.ClientId)

	So(payment.DeleteCustomerForGroup(groupName), ShouldBeNil)
}
Exemplo n.º 4
0
func TestPresenceDailyFetchActiveAccounts(t *testing.T) {
	tests.WithRunner(t, func(r *runner.Runner) {
		Convey("With given presence data", t, func() {
			acc1, _, groupName := CreateRandomGroupDataWithChecks()

			gr, err := modelhelper.GetGroup(groupName)
			tests.ResultedWithNoErrorCheck(gr, err)
			err = modelhelper.MakeAdmin(bson.ObjectIdHex(acc1.OldId), gr.Id)
			So(err, ShouldBeNil)

			p1 := &PresenceDaily{
				AccountId: acc1.Id,
				GroupName: groupName,
				CreatedAt: time.Now().UTC(),
			}
			So(p1.Create(), ShouldBeNil)
			ses, err := modelhelper.FetchOrCreateSession(acc1.Nick, groupName)
			So(err, ShouldBeNil)
			So(ses, ShouldNotBeNil)

			for i := 0; i < 5; i++ {
				// create accounts
				acc2 := CreateAccountInBothDbsWithCheck()

				// add them to presence
				p1 := &PresenceDaily{
					AccountId: acc2.Id,
					GroupName: groupName,
					CreatedAt: time.Now().UTC(),
				}
				So(p1.Create(), ShouldBeNil)
			}

			Convey("FetchActiveAccounts should not work properly if query is nil", func() {
				query := request.NewQuery()
				c1, err := (&PresenceDaily{}).FetchActiveAccounts(query)
				So(err, ShouldNotBeNil)
				So(c1, ShouldBeNil)

				Convey("FetchActiveAccounts should work properly", func() {
					query := request.NewQuery().SetDefaults()
					query.GroupName = groupName
					c1, err := (&PresenceDaily{}).FetchActiveAccounts(query)
					So(err, ShouldBeNil)
					So(c1, ShouldNotBeNil)
				})

				Convey("Pagination skip should work properly", func() {
					query := request.NewQuery().SetDefaults()
					query.GroupName = groupName
					query.Skip = 20
					c1, err := (&PresenceDaily{}).FetchActiveAccounts(query)
					So(err, ShouldNotBeNil)
					So(err, ShouldEqual, bongo.RecordNotFound)
					So(c1, ShouldBeNil)

					Convey("Pagination limit should work properly", func() {
						query := request.NewQuery().SetDefaults()
						query.GroupName = groupName
						query.Limit = 4
						c1, err := (&PresenceDaily{}).FetchActiveAccounts(query)
						So(err, ShouldBeNil)
						So(c1, ShouldNotBeNil)
						So(len(c1.Accounts), ShouldEqual, 4)
					})
				})
			})
		})
	})
}