func TestApiCreateEventShow_400(t *testing.T) {
	var genParams = func(omitName string) url.Values {
		params := url.Values{
			"open_at":    []string{"2015-01-02T06:00:00Z"},
			"start_at":   []string{"2015-01-02T07:00:00Z"},
			"latitude":   []string{"37.39"},
			"longitude":  []string{"140.38"},
			"venue_id":   []string{"153237058036933"},
			"venue_name": []string{"郡山市民文化センター"},
			"pia_link":   []string{"http://pia.jp/link"},
			"ya_keyword": []string{"郡山"},
		}
		params.Del(omitName)
		return params
	}

	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
		p := app.TestApp().Api.Path("/events/event1/shows")
		var testOmitParams = []string{
			"open_at", "start_at", "latitude", "longitude", "venue_id", "venue_name", // "pia_link", "ya_keyword",
		}
		for _, paramName := range testOmitParams {
			req := ts.PostForm(p, genParams(paramName))
			lib.SetApiTokenForTest(req, lib.Admin)
			res := req.RouteTo(app.TestApp().Routes())
			assert.HttpStatus(400, res)
		}
	})
}
Exemple #2
0
func TestApiUpdateEvent(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		appCtx := apptest.NewAppContextFromTestServer(app.TestApp().App, ts)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiUpdateEvent.json", nil)
		d := NewEventDriver(appCtx)

		var e event.Event

		p := app.TestApp().Api.Path("/events/event1.json")
		req := ts.PutForm(p, url.Values{
			"title":      []string{"Updated Title"},
			"link":       []string{"http://www.up.example.com/"},
			"image_link": []string{"http://www.up.example.com/img.png"},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.TestApp().Routes())
		assert.HttpStatus(200, res)

		err := util.WaitFor(func() bool {
			d.Load("event1", &e)
			return e.Title == "Updated Title"
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm the show has been inserted within timeout window.")

		assert.EqStr("Updated Title", e.Title, "Title")
		assert.EqStr("http://www.up.example.com/", e.Link, "Link")
		assert.EqStr("http://www.up.example.com/img.png", e.ImageLink, "ImageLink")
	})
}
Exemple #3
0
func TestApiCreateEvent_400(t *testing.T) {
	var genParams = func(omitName string) url.Values {
		params := url.Values{
			"title":      []string{"test tour title"},
			"link":       []string{"http://www.example.com/"},
			"image_link": []string{"http://www.example.com/img.png"},
		}
		params.Del(omitName)
		return params
	}

	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
		p := app.TestApp().Api.Path("/events/")
		var testOmitParams = []string{
			"title", "link", "image_link",
		}
		for _, paramName := range testOmitParams {
			req := ts.PostForm(p, genParams(paramName))
			lib.SetApiTokenForTest(req, lib.Admin)
			res := req.RouteTo(app.TestApp().Routes())
			assert.HttpStatus(400, res)
		}
	})
}
func TestApiCreateEventShow_404(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
		p := app.TestApp().Api.Path("/events/notexit/shows")
		req := ts.PostForm(p, url.Values{})
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.TestApp().Routes())
		assert.HttpStatus(404, res)
	})
}
func TestApiListEventShow(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiListEventShow.json", nil)
		var respJson []event.Show
		p := app.TestApp().Api.Path("/events/event1/shows")
		req := ts.Get(p)
		res := req.RouteTo(app.TestApp().Routes())
		assert.HttpStatus(200, res)
		res.Json(&respJson)
		assert.EqInt(1, len(respJson), "shows should return 1 element")
		assert.EqStr("event1-show1", respJson[0].Id, "Id")
		assert.EqStr("event1", respJson[0].EventId, "EventId")
	})
}
Exemple #6
0
func TestNewEventShowList(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := wcg.NewAssert(t)
		appCtx := apptest.NewAppContextFromTestServer(app.TestApp().App, ts)
		test.DatastoreFixture(ts.Context, "./fixtures/TestNewEventShowList.json", nil)

		var showList []event.Show
		d := NewShowDriver(appCtx)
		d.NewQuery().GetAll(&showList)
		assert.EqInt(2, len(showList), "2 Show entities must be prepared.")
		list, _ := NewEventShowList(appCtx, showList)

		// showList[1] is orphan Show entity so that only 1 entity is returned.
		assert.EqInt(1, len(list), "1 eventShow must be returned.")
	})
}
func TestApiCreateEventShow(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		appCtx := apptest.NewAppContextFromTestServer(app.TestApp().App, ts)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
		d := NewShowDriver(appCtx)

		var respJson map[string]interface{}
		var show event.Show
		p := app.TestApp().Api.Path("/events/event1/shows")
		req := ts.PostForm(p, url.Values{
			"open_at":    []string{"2015-01-02T06:00:00Z"},
			"start_at":   []string{"2015-01-02T07:00:00Z"},
			"latitude":   []string{"37.39"},
			"longitude":  []string{"140.38"},
			"venue_id":   []string{"153237058036933"},
			"venue_name": []string{"郡山市民文化センター"},
			"pia_link":   []string{"http://pia.jp/link"},
			"ya_keyword": []string{"郡山"},
		})
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.TestApp().Routes())
		assert.HttpStatus(201, res)

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 1
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm the show has been inserted within timeout window.")

		res.Json(&respJson)
		d.Load(respJson["id"].(string), "event1", &show)
		open_at, _ := util.ParseDateTime("2015-01-02T06:00:00Z")
		start_at, _ := util.ParseDateTime("2015-01-02T07:00:00Z")
		assert.EqTime(open_at, show.OpenAt, "OpenAt")
		assert.EqTime(start_at, show.StartAt, "StartAt")
		assert.EqFloat64(37.39, show.Latitude, "Latitude")
		assert.EqFloat64(140.38, show.Longitude, "Longitude")
		assert.EqStr("153237058036933", show.VenueId, "VenueId")
		assert.EqStr("郡山市民文化センター", show.VenueName, "VenueName")
		assert.EqStr("http://pia.jp/link", show.PiaLink, "PiaLink")
		assert.EqStr("郡山", show.YAKeyword, "YAKeyword")
	})
}
func TestApiDeleteEventShow(t *testing.T) {
	test.RunTestServer(func(ts *test.TestServer) {
		assert := test.NewAssert(t)
		appCtx := apptest.NewAppContextFromTestServer(app.TestApp().App, ts)
		test.DatastoreFixture(ts.Context, "./fixtures/TestApiDeleteEventShow.json", nil)
		d := NewShowDriver(appCtx)

		p := app.TestApp().Api.Path("/events/event1/shows/event1-show1.json")
		req := ts.Delete(p)
		lib.SetApiTokenForTest(req, lib.Admin)
		res := req.RouteTo(app.TestApp().Routes())
		assert.HttpStatus(200, res)

		err := util.WaitFor(func() bool {
			c, _ := d.NewQuery().Count()
			return c == 0
		}, util.DefaultWaitForTimeout)
		assert.Nil(err, "Confirm the show has been inserted within timeout window.")
	})
}
Exemple #9
0
func Test_generateYACrawlerKeywords(t *testing.T) {
	// set base time to skip
	now = func() time.Time {
		return time.Date(2015, 01, 01, 15, 0, 0, 0, time.UTC)
	}

	test.RunTestServer(func(ts *test.TestServer) {
		assert := wcg.NewAssert(t)
		appCtx := apptest.NewAppContextFromTestServer(app.TestApp().App, ts)
		test.DatastoreFixture(ts.Context, "./fixtures/Test_generateYACrawlerKeywords.json", nil)

		keywords, err := generateYACrawlerKeywords(appCtx)
		assert.Nil(err, "generateYACCrawlerKeywords should not return an error")
		assert.EqInt(2, len(keywords), "generateYACCrawlerKeywords should return 1 keyword object.")

		// no updates should happen
		keywords, err = generateYACrawlerKeywords(appCtx)
		assert.Nil(err, "generateYACCrawlerKeywords should not return an error")
		assert.EqInt(0, len(keywords), "generateYACCrawlerKeywords should return 1 keyword object.")
	})
}