Esempio n. 1
0
func Test_API_Config_Get_Default(t *testing.T) {
	assert := gaetest.NewAssert(t)
	assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Config_Get.json", nil), "fixture")
	testUser := httptest.NewTestUser().SetID("facebook:6789")
	dummy := ts.GET("/")

	configs.TemporarySetConfig(dummy.Request,
		"facebook_page_id", "12345",
		func() {
			messenger.TemporaryOptIn(dummy.Request,
				"12345", testUser.ID(),
				func() {
					var notif pt.MessengerNotification
					req := ts.GET("/api/intern/pt/configs/facebook%3A6789/messenger.json")
					req.Request.User = testUser
					helper.TemporaryAllow(req, "family", func() {
						res := req.RouteTo(instance.Routes())
						assert.HTTPStatus(200, res)
						assert.JSONResponse(&notif, res)
						assert.EqStr("facebook:6789", notif.UserID, "MessengerNotification.UserID")
						assert.OK(!notif.Summary, "MessengerNotification.Summary")
						assert.OK(!notif.OnStart, "MessengerNotification.OnStart")
						assert.OK(!notif.OnEnd, "MessengerNotification.OnEnd")
					})
				},
			)
		},
	)
}
Esempio n. 2
0
func Test_API_Config_Put(t *testing.T) {
	assert := gaetest.NewAssert(t)
	testUser := httptest.NewTestUser().SetID("facebook:12345")
	dummy := ts.GET("/")

	configs.TemporarySetConfig(dummy.Request,
		"facebook_page_id", "12345",
		func() {
			messenger.TemporaryOptIn(dummy.Request,
				"12345", testUser.ID(),
				func() {
					var notif pt.MessengerNotification
					req := ts.PUTForm("/api/intern/pt/configs/facebook%3A12345/messenger.json", url.Values{
						"id":       []string{"messenger"},
						"user_id":  []string{"testuser"},
						"summary":  []string{"true"},
						"on_start": []string{"true"},
						"on_end":   []string{"false"},
					})
					req.Request.User = testUser
					helper.TemporaryAllow(req, "family", func() {
						res := req.RouteTo(instance.Routes())
						assert.HTTPStatus(200, res)
						assert.JSONResponse(&notif, res)
						assert.EqStr("testuser", notif.UserID, "MessengerNotification.UserID")
						assert.OK(notif.Summary, "MessengerNotification.Summary")
						assert.OK(notif.OnStart, "MessengerNotification.OnStart")
						assert.OK(!notif.OnEnd, "MessengerNotification.OnEnd")
					})
				},
			)
		},
	)
}
Esempio n. 3
0
func Test_API_Config_Get_NoOptIn(t *testing.T) {
	assert := gaetest.NewAssert(t)
	testUser := httptest.NewTestUser().SetID("facebook:12345")
	dummy := ts.GET("/")
	configs.TemporarySetConfig(dummy.Request,
		"facebook_page_id", "12345",
		func() {
			req := ts.GET("/api/intern/pt/configs/facebook%3A12345/messenger.json")
			req.Request.User = testUser

			helper.TemporaryAllow(req, "family", func() {
				res := req.RouteTo(instance.Routes())
				assert.HTTPStatus(403, res)
			})
		},
	)
}