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")
					})
				},
			)
		},
	)
}
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")
					})
				},
			)
		},
	)
}
Exemple #3
0
func Test_RequireMessengerOptIn(t *testing.T) {
	assert := gaetest.NewAssert(t)
	router := wcg.NewRouter()
	router.GET("/",
		RequireMessengerOptIn(""),
		wcg.AnonymousHandler(func(res *wcg.Response, req *wcg.Request) {
			res.WriteString("OK")
		}),
	)
	req := ts.GET("/")
	res := req.RouteTo(router)
	assert.HTTPStatus(403, res)

	configs.TemporarySetConfig(ts.GET("dummy").Request, "facebook_page_id", "1234", func() {
		messenger.TemporaryOptIn(ts.GET("dummy").Request, "1234", wcg.GuestUser.ID(), func() {
			req := ts.GET("/")
			res := req.RouteTo(router)
			assert.HTTPStatus(200, res)
		})
	})
}