Skip to content

Commit

Permalink
Add test for GET project environment endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
diyan committed Feb 14, 2017
1 parent 93e18b5 commit e4d4a31
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/endpoints/project_environments_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package api_test

func (t *testSuite) TestProjectEnvironment_Get() {
t.T().Skip("Not yet implemented")
t.Factory.SaveOrganization(t.Factory.MakeOrganization())
t.Factory.SaveProject(t.Factory.MakeProject())
t.Factory.SaveEnvironment(t.Factory.MakeEnvironment())

res, bodyStr, errs := t.Client.Get("http://example.com/api/0/projects/acme-team/acme/environments/").End()
t.Nil(errs)
t.Equal(200, res.StatusCode)
t.JSONEq(`[{
"id": "1",
"name": ""
}]`,
bodyStr)
}
12 changes: 12 additions & 0 deletions db/store/project_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ func (s ProjectStore) SaveProject(project models.Project) error {
return errors.Wrap(err, "failed to save project")
}

func (s ProjectStore) SaveEnvironment(environment models.Environment) error {
db, err := db.FromE(s.c)
if err != nil {
return errors.Wrap(err, "failed to save project environment")
}
_, err = db.InsertInto("sentry_environment").
Columns("id", "project_id", "name", "date_added").
Record(environment).
Exec()
return errors.Wrap(err, "failed to save project environment")
}

func (s ProjectStore) SaveTags(tags ...*models.TagKey) error {
db, err := db.FromE(s.c)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions migrations/postgres/0001_initial.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ create table sentry_project (
);


create table sentry_environment (
id serial not null,
project_id integer not null,
name character varying(64) not null,
date_added timestamp with time zone not null,
constraint sentry_environment_project_id_check check ((project_id >= 0))
);


create table sentry_filterkey (
id serial not null,
project_id integer not null,
Expand Down
9 changes: 9 additions & 0 deletions testutil/factory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func (tf TestFactory) MakeProject() models.Project {
}
}

func (tf TestFactory) MakeEnvironment() models.Environment {
return models.Environment{
ID: 1,
ProjectID: 1,
Name: "",
DateCreated: time_of_2999_01_01__00_00_00,
}
}

func (tf TestFactory) MakeUser() models.User {
return models.User{
ID: 1,
Expand Down
5 changes: 5 additions & 0 deletions testutil/factory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func (tf TestFactory) SaveProject(project models.Project) {
tf.noError(projectStore.SaveProject(project))
}

func (tf TestFactory) SaveEnvironment(environment models.Environment) {
projectStore := store.NewProjectStore(tf.ctx)
tf.noError(projectStore.SaveEnvironment(environment))
}

func (tf TestFactory) SaveTags(tags ...*models.TagKey) {
projectStore := store.NewProjectStore(tf.ctx)
tf.noError(projectStore.SaveTags(tags...))
Expand Down

0 comments on commit e4d4a31

Please sign in to comment.