Skip to content

Commit

Permalink
Add Upsert Dictionary error test
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Aug 21, 2024
1 parent 752c426 commit 6ba8426
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
54 changes: 54 additions & 0 deletions backend/graph/schema.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2187,5 +2187,59 @@ New Front 2 裏面2
testGraphQLQuery(t, e, jsonInput, expected, "data.upsertDictionary.nodes.id")
})

t.Run("Upsert Dictionary with Invalid Format", func(t *testing.T) {
t.Helper()
t.Parallel()

// Generate dummy data
userService := services.NewUserService(db, 20)
cardGroupService := services.NewCardGroupService(db, 20)
roleService := services.NewRoleService(db, 20)

ctx := context.Background()
createdGroup, _, _ := testutils.CreateUserAndCardGroup(ctx, userService, cardGroupService, roleService)

// Create invalid dictionary data
invalidDictionary := base64.StdEncoding.EncodeToString([]byte(`Invalid Dictionary Data Without Correct Format`))

input := model.UpsertDictionary{
Dictionary: invalidDictionary,
CardgroupID: createdGroup.ID,
}

// Create the GraphQL query
jsonInput, _ := json.Marshal(map[string]interface{}{
"query": `mutation ($input: UpsertDictionary!) {
upsertDictionary(input: $input) {
nodes {
id
front
back
interval_days
cardGroupID
}
}
}`,
"variables": map[string]interface{}{
"input": input,
},
})

// Updated expected error response
expected := `{
"errors": [
{
"message": "failed to upsert cards: : failed to process dictionary: [line : 1 : syntax error: unexpected $end, expecting DEFINITION]",
"path": ["upsertDictionary"]
}
],
"data": {
"upsertDictionary": null
}
}`

// Execute the GraphQL query and verify the result
testGraphQLQuery(t, e, jsonInput, expected)
})
})
}
21 changes: 21 additions & 0 deletions backend/pkg/usecases/swipe_manager/swipe_manager_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ const (
INWHILE = 4
)

// Define a type for the constants
type Difficulty int

// Implement the String method for the Difficulty type
func (d Difficulty) String() string {
switch d {
case DEFAULT:
return "DEFAULT"
case DIFFICULT:
return "DIFFICULT"
case GOOD:
return "GOOD"
case EASY:
return "EASY"
case INWHILE:
return "INWHILE"
default:
return "UNKNOWN"
}
}

type swipeManagerUsecase struct {
services services.Services
}
Expand Down

0 comments on commit 6ba8426

Please sign in to comment.