MCPcopy
hub / github.com/dgraph-io/dgraph / checkAddUpdateCase

Function checkAddUpdateCase

graphql/resolve/auth_test.go:736–793  ·  view source on GitHub ↗
(
	t *testing.T,
	gqlSchema schema.Schema,
	tcase AuthQueryRewritingCase,
	rewriter func() MutationRewriter,
	authMeta *testutil.AuthMeta)

Source from the content-addressed store, hash-verified

734}
735
736func checkAddUpdateCase(
737 t *testing.T,
738 gqlSchema schema.Schema,
739 tcase AuthQueryRewritingCase,
740 rewriter func() MutationRewriter,
741 authMeta *testutil.AuthMeta) {
742 // -- Arrange --
743 var vars map[string]interface{}
744 if tcase.Variables != "" {
745 require.NoError(t, json.Unmarshal([]byte(tcase.Variables), &vars))
746 }
747
748 op, err := gqlSchema.Operation(
749 &schema.Request{
750 Query: tcase.GQLQuery,
751 Variables: vars,
752 })
753 require.NoError(t, err)
754 mut := test.GetMutation(t, op)
755
756 // Clear the map and initialize it.
757 authMeta.AuthVars = make(map[string]interface{})
758 for k, v := range tcase.JWTVar {
759 authMeta.AuthVars[k] = v
760 }
761
762 ctx := context.Background()
763 if !authMeta.ClosedByDefault {
764 ctx, err = authMeta.AddClaimsToContext(ctx)
765 require.NoError(t, err)
766 }
767
768 ex := &authExecutor{
769 t: t,
770 json: tcase.Json,
771 queryResultJSON: tcase.QueryJSON,
772 dgQuerySec: tcase.DGQuerySec,
773 uids: tcase.Uids,
774 dgQuery: tcase.DGQuery,
775 authQuery: tcase.AuthQuery,
776 authJson: tcase.AuthJson,
777 skipAuth: tcase.SkipAuth,
778 }
779 resolver := NewDgraphResolver(rewriter(), ex)
780
781 // -- Act --
782 resolved, success := resolver.Resolve(ctx, mut)
783
784 // -- Assert --
785 // most cases are built into the authExecutor
786 if tcase.Error != nil {
787 require.False(t, success, "Mutation should have failed as it throws an error")
788 require.NotNil(t, resolved.Err)
789 require.Equal(t, tcase.Error.Error(), resolved.Err.Error())
790 } else {
791 require.True(t, success, "Mutation should have not failed as it did not throw an error")
792 }
793}

Callers 2

mutationAddFunction · 0.85
mutationUpdateFunction · 0.85

Calls 6

GetMutationFunction · 0.92
NewDgraphResolverFunction · 0.85
AddClaimsToContextMethod · 0.80
OperationMethod · 0.65
ResolveMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected