func Test_EntityQuery(t *testing.T) { assert := gaetest.NewAssert(t) router := wcg.NewRouter() router.GET("/api/", EntityQuery(testEntity.Query().Limit(2)), ) gaetest.CleanupDatastore(ts.Context) gaetest.FixtureFromMap(ts.Context, []map[string]interface{}{ map[string]interface{}{"_kind": testEntity.String(), "_key": "1", "ID": "1"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "2", "ID": "2"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "3", "ID": "3"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "4", "ID": "4"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "5", "ID": "5"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "6", "ID": "6"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "7", "ID": "7"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "8", "ID": "8"}, map[string]interface{}{"_kind": testEntity.String(), "_key": "9", "ID": "9"}, }) var got entities.Pagination req := ts.GET("/api/") res := req.RouteTo(router) assert.HTTPStatus(200, res) assert.JSONResponse(&got, res) assert.EqInt(2, got.Length()) assert.EqInt(2, got.Next.N) assert.EqInt(1, got.Next.P) assert.Nil(got.Previous) // TODO: got does not has []TEntity, but has []map[string]interface{}. // Need to provide a way to make got have []TEntity or []*TEntity }
func Test_API_IEPGRecord_List(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_List.json", nil, "intern.pt"), "fixture") lib.TemporarySetNow(now, func() { req := ts.GET("/api/intern/pt/iepg/records/") res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) var got entities.Pagination assert.JSONResponse(&got, res) assert.EqInt(1, got.Length(), "%v", got) }) }
func Test_EntityQuery_Empty(t *testing.T) { assert := gaetest.NewAssert(t) router := wcg.NewRouter() router.GET("/api/", EntityQuery(testEntity.Query().Limit(2)), ) gaetest.CleanupDatastore(ts.Context) var got entities.Pagination req := ts.GET("/api/") res := req.RouteTo(router) assert.HTTPStatus(200, res) assert.JSONResponse(&got, res) assert.EqInt(0, got.Length()) }
func Test_API_Task_List(t *testing.T) { assert := gaetest.NewAssert(t) assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Task_List.json", nil), "fixture") now, _ := wcg.ParseDateTime("2016-01-10T00:00:00Z") lib.TemporarySetNow(now, func() { req := ts.GET("/api/admin/tasks/") res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) var got entities.Pagination assert.JSONResponse(&got, res) assert.EqInt(0, got.Length()) }) now, _ = wcg.ParseDateTime("2016-01-09T00:00:00Z") lib.TemporarySetNow(now, func() { req := ts.GET("/api/admin/tasks/") res := req.RouteTo(instance.Routes()) assert.HTTPStatus(200, res) var got entities.Pagination assert.JSONResponse(&got, res) assert.EqInt(1, got.Length()) }) }