-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
165 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#offers api | ||
#https://github.com/topfreegames/offers | ||
|
||
#Licensed under the MIT license: | ||
#http://www.opensource.org/licenses/mit-license | ||
#Copyright © 2017 Top Free Games <backend@tfgco.com> | ||
|
||
- | ||
id: 3393cd15-5b5a-4cfb-9725-ddbde660a727 | ||
name: game-1 | ||
created_at: 2016-01-01 12:30:12 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// offers api | ||
// https://github.com/topfreegames/offers | ||
// | ||
// Licensed under the MIT license: | ||
// http://www.opensource.org/licenses/mit-license | ||
// Copyright © 2017 Top Free Games <backend@tfgco.com> | ||
|
||
package models | ||
|
||
import ( | ||
"github.com/mgutz/dat" | ||
|
||
"github.com/jmoiron/sqlx/types" | ||
) | ||
|
||
//Game represents a tenant in offers API | ||
type Game struct { | ||
ID string `db:"id"` | ||
Name string `db:"name"` | ||
Metadata types.JSONText `db:"metadata"` | ||
CreatedAt dat.NullTime `db:"created_at"` | ||
UpdatedAt dat.NullTime `db:"updated_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// offers api | ||
// https://github.com/topfreegames/offers | ||
// | ||
// Licensed under the MIT license: | ||
// http://www.opensource.org/licenses/mit-license | ||
// Copyright © 2017 Top Free Games <backend@tfgco.com> | ||
|
||
package models_test | ||
|
||
import ( | ||
"github.com/jmoiron/sqlx/types" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
uuid "github.com/satori/go.uuid" | ||
"github.com/topfreegames/offers/models" | ||
) | ||
|
||
var _ = Describe("Games Model", func() { | ||
Describe("Game Instance", func() { | ||
It("Shoud load a game", func() { | ||
var game models.Game | ||
err := db. | ||
Select("*"). | ||
From("games"). | ||
Where("id = $1", "3393cd15-5b5a-4cfb-9725-ddbde660a727"). | ||
QueryStruct(&game) | ||
|
||
Expect(game.ID).To(Equal("3393cd15-5b5a-4cfb-9725-ddbde660a727")) | ||
Expect(game.Name).To(Equal("game-1")) | ||
Expect(game.Metadata.String()).To(BeEquivalentTo("{}")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
It("Should create game", func() { | ||
meta := types.JSONText( | ||
[]byte(` | ||
{"qwe": 123} | ||
`), | ||
) | ||
|
||
game := models.Game{ | ||
Name: uuid.NewV4().String(), | ||
Metadata: meta, | ||
} | ||
err := db. | ||
InsertInto("games"). | ||
Columns("name", "metadata"). | ||
Record(&game). | ||
Returning("id", "created_at", "updated_at"). | ||
QueryStruct(&game) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// offers api | ||
// https://github.com/topfreegames/offers | ||
// | ||
// Licensed under the MIT license: | ||
// http://www.opensource.org/licenses/mit-license | ||
// Copyright © 2017 Top Free Games <backend@tfgco.com> | ||
|
||
package testing | ||
|
||
import ( | ||
"github.com/go-testfixtures/testfixtures" | ||
runner "github.com/mgutz/dat/sqlx-runner" | ||
"github.com/topfreegames/offers/models" | ||
) | ||
|
||
var ( | ||
fixtures *testfixtures.Context | ||
) | ||
|
||
//GetTestDB returns a connection to the test database | ||
func GetTestDB() (*runner.DB, error) { | ||
return models.GetDB( | ||
"localhost", "offers_test", 8585, "disable", | ||
"offers_test", "", | ||
10, 10, | ||
) | ||
} | ||
|
||
//LoadFixtures into the DB | ||
func LoadFixtures(db *runner.DB) error { | ||
var err error | ||
|
||
if fixtures == nil { | ||
// creating the context that hold the fixtures | ||
// see about all compatible databases in this page below | ||
fixtures, err = testfixtures.NewFolder(db.DB.DB, &testfixtures.PostgreSQL{}, "../fixtures") | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if err := fixtures.Load(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |