Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Aug 24, 2024
1 parent fc2fb35 commit 3d501e2
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions backend/graph/schema.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
// Testify suite does not allow to run tests Parallel, which is considered inevitable for resolver tests.
var e *echo.Echo
var db *gorm.DB
var sv services.Services
var migrationFilePath = "../db/migrations"

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -68,15 +69,15 @@ func NewRouter(db *gorm.DB) *echo.Echo {
e.Use(middlewares.DatabaseCtxMiddleware(db))
e.Use(middlewares.TransactionMiddleware())

service := services.New(db)
usecase := usecases.New(service)
sv = services.New(db)
usecase := usecases.New(sv)
validateWrapper := validator.NewValidateWrapper()
resolver := &graph.Resolver{
DB: db,
Srv: service,
Srv: sv,
U: usecase,
VW: validateWrapper,
Loaders: graph.NewLoaders(service),
Loaders: graph.NewLoaders(sv),
}

srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: resolver}))
Expand Down Expand Up @@ -161,28 +162,19 @@ func TestGraphQLQueries(t *testing.T) {
t.Helper()
t.Parallel()

userService := sv.(services.UserService)
cardGroupService := sv.(services.CardGroupService)
roleService := sv.(services.RoleService)
cardService := sv.(services.CardService)
ctx := context.Background()

testutils.RunServersTest(t, db, func(t *testing.T) {
t.Run("Card Query", func(t *testing.T) {
t.Parallel()

now := time.Now().UTC()
cardGroup := repository.Cardgroup{
Name: "Card Query Test CardGroup",
Created: now,
Updated: now,
createdCard, _, _, err := testutils.CreateUserCardAndCardGroup(ctx, userService, cardGroupService, roleService, cardService)
if err != nil {
t.Fatal(err)
}
db.Create(&cardGroup)

card := repository.Card{
Front: "Test Card Front",
Back: "Test Card Back",
ReviewDate: now,
IntervalDays: 1,
CardGroupID: cardGroup.ID,
Created: now,
Updated: now,
}
db.Create(&card)

jsonInput, _ := json.Marshal(map[string]interface{}{
"query": `query ($id: ID!) {
Expand All @@ -197,20 +189,22 @@ func TestGraphQLQueries(t *testing.T) {
}
}`,
"variables": map[string]interface{}{
"id": card.ID,
"id": createdCard.ID,
},
})

expected := fmt.Sprintf(`{
"data": {
"card": {
"id": %d,
"front": "Test Card Front",
"back": "Test Card Back",
"interval_days": 1
}
}
}`, card.ID)
expectedCard := map[string]interface{}{
"id": createdCard.ID,
"front": createdCard.Front,
"back": createdCard.Back,
"interval_days": 1,
}
expectedData, _ := json.Marshal(map[string]interface{}{
"data": map[string]interface{}{
"card": expectedCard,
},
})
expected := string(expectedData)

testGraphQLQuery(t, e, jsonInput, expected, "data.card.created", "data.card.updated", "data.card.review_date")
})
Expand Down

0 comments on commit 3d501e2

Please sign in to comment.