From 7de90124b48f5634ff0fc4cfa0923785caba29fe Mon Sep 17 00:00:00 2001 From: KCarretto Date: Sat, 23 Mar 2024 23:16:13 +0000 Subject: [PATCH] fix empty check; add test --- tavern/internal/graphql/mutation.resolvers.go | 2 +- .../mutations/createQuest/NoBeacons.yml | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tavern/internal/graphql/testdata/mutations/createQuest/NoBeacons.yml diff --git a/tavern/internal/graphql/mutation.resolvers.go b/tavern/internal/graphql/mutation.resolvers.go index e611e8fc4..d17df58d2 100644 --- a/tavern/internal/graphql/mutation.resolvers.go +++ b/tavern/internal/graphql/mutation.resolvers.go @@ -60,7 +60,7 @@ func (r *mutationResolver) DropAllData(ctx context.Context) (bool, error) { // CreateQuest is the resolver for the createQuest field. func (r *mutationResolver) CreateQuest(ctx context.Context, beaconIDs []int, input ent.CreateQuestInput) (*ent.Quest, error) { // Ensure at least one Beacon ID provided - if beaconIDs == nil { + if beaconIDs == nil || len(beaconIDs) < 1 { return nil, fmt.Errorf("must provide at least one beacon id") } diff --git a/tavern/internal/graphql/testdata/mutations/createQuest/NoBeacons.yml b/tavern/internal/graphql/testdata/mutations/createQuest/NoBeacons.yml new file mode 100644 index 000000000..3bc6fc876 --- /dev/null +++ b/tavern/internal/graphql/testdata/mutations/createQuest/NoBeacons.yml @@ -0,0 +1,38 @@ +state: | + INSERT INTO `users` (id,oauth_id,photo_url,name,session_token,access_token,is_activated,is_admin) + VALUES (5,"test_oauth_id","https://photos.com","test","secretToken","accessToken",true,true); + INSERT INTO `hosts` (id, name, identifier, platform, created_at, last_modified_at) + VALUES (1010,"db1","EXISTING-HOST", "PLATFORM_UNSPECIFIED", "2023-03-04 14:51:13", "2023-03-04 14:51:13"); + INSERT INTO `tomes` (id, name, description, author, eldritch, hash, created_at, last_modified_at) + VALUES (2000,"Test Tome","Used in a unit test :D", "kcarretto", "print('Hello World!')", "abcdefg", "2023-03-04 14:51:13", "2023-03-04 14:51:13"); +requestor: + session_token: secretToken +query: | + mutation CreateQuestWithNoBeacons($beaconIDs: [ID!]!, $input: CreateQuestInput!) { + createQuest(beaconIDs:$beaconIDs, input:$input) { + name + tome { + id + name + } + tasks { + edges { + node { + beacon { + id + } + quest { + name + } + } + } + } + } + } +variables: + beaconIDs: [] + input: + name: "WonderfulQuest" + tomeID: "2000" + +expected_error: "must provide at least one beacon id"