Skip to content

Commit

Permalink
fix: Add missing delta payload (#2306)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2299

## Description

This PR fixes a regression bug and adds integration tests to ensure that
future changes don't break the expected query results
  • Loading branch information
fredcarle authored Feb 12, 2024
1 parent 398ffbc commit 31297f8
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 13 deletions.
2 changes: 1 addition & 1 deletion planner/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (n *dagScanNode) dagBlockToNodeDoc(block blocks.Block) (core.Doc, []*ipld.L
}

n.commitSelect.DocumentMapping.SetFirstOfName(&commit, request.HeightFieldName, int64(prio))
n.commitSelect.DocumentMapping.SetFirstOfName(&commit, request.DeltaFieldName, request.DeltaArgData)
n.commitSelect.DocumentMapping.SetFirstOfName(&commit, request.DeltaFieldName, delta[request.DeltaArgData])
n.commitSelect.DocumentMapping.SetFirstOfName(&commit, request.FieldNameFieldName, fieldName)
n.commitSelect.DocumentMapping.SetFirstOfName(&commit, request.FieldIDFieldName, fieldID)

Expand Down
20 changes: 10 additions & 10 deletions request/graphql/schema/types/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,47 @@ var (
Name: request.CommitTypeName,
Description: commitDescription,
Fields: gql.Fields{
"height": &gql.Field{
request.HeightFieldName: &gql.Field{
Description: commitHeightFieldDescription,
Type: gql.Int,
},
"cid": &gql.Field{
request.CidFieldName: &gql.Field{
Description: commitCIDFieldDescription,
Type: gql.String,
},
request.DocIDArgName: &gql.Field{
Description: commitDocIDFieldDescription,
Type: gql.String,
},
"collectionID": &gql.Field{
request.CollectionIDFieldName: &gql.Field{
Description: commitCollectionIDFieldDescription,
Type: gql.Int,
},
"schemaVersionId": &gql.Field{
request.SchemaVersionIDFieldName: &gql.Field{
Description: commitSchemaVersionIDFieldDescription,
Type: gql.String,
},
"fieldName": &gql.Field{
request.FieldNameFieldName: &gql.Field{
Description: commitFieldNameFieldDescription,
Type: gql.String,
},
"fieldId": &gql.Field{
request.FieldIDFieldName: &gql.Field{
Type: gql.String,
Description: commitFieldIDFieldDescription,
},
"delta": &gql.Field{
request.DeltaFieldName: &gql.Field{
Description: commitDeltaFieldDescription,
Type: gql.String,
},
"links": &gql.Field{
request.LinksFieldName: &gql.Field{
Description: commitLinksDescription,
Type: gql.NewList(CommitLinkObject),
},
"_count": &gql.Field{
request.CountFieldName: &gql.Field{
Description: CountFieldDescription,
Type: gql.Int,
Args: gql.FieldConfigArgument{
"field": &gql.ArgumentConfig{
request.FieldName: &gql.ArgumentConfig{
Type: commitCountFieldArg,
},
},
Expand Down
117 changes: 115 additions & 2 deletions tests/integration/query/commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ func TestQueryCommitsWithFieldIDFieldWithUpdate(t *testing.T) {
testUtils.Request{
Request: `
query {
commits {
fieldId
}
Expand Down Expand Up @@ -315,3 +313,118 @@ func TestQueryCommitsWithFieldIDFieldWithUpdate(t *testing.T) {

testUtils.ExecuteTestCase(t, test)
}

func TestQuery_CommitsWithAllFieldsWithUpdate_NoError(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
updateUserCollectionSchema(),
testUtils.CreateDoc{
Doc: `{
"name": "John",
"age": 21
}`,
},
testUtils.UpdateDoc{
Doc: `{
"age": 22
}`,
},
testUtils.Request{
Request: `
query {
commits {
cid
collectionID
delta
docID
fieldId
fieldName
height
links {
cid
name
}
}
}
`,
Results: []map[string]any{
{
"cid": "bafybeiddpjl27ulw2yo4ohup6gr2wob3pwagqw2rbeaxxodv4ljelnu7ve",
"collectionID": int64(1),
"delta": testUtils.CBORValue(22),
"docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"fieldId": "1",
"fieldName": "age",
"height": int64(2),
"links": []map[string]any{
{
"cid": "bafybeieikx6l2xead2dzsa5wwy5irxced2eddyq23jkp4csf5igoob7diq",
"name": "_head",
},
},
},
{
"cid": "bafybeieikx6l2xead2dzsa5wwy5irxced2eddyq23jkp4csf5igoob7diq",
"collectionID": int64(1),
"delta": testUtils.CBORValue(21),
"docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"fieldId": "1",
"fieldName": "age",
"height": int64(1),
"links": []map[string]any{},
},
{
"cid": "bafybeiehcr3diremeja2ndk2osux647v5fc7s353h7pbvrnsagw4paugku",
"collectionID": int64(1),
"delta": testUtils.CBORValue("John"),
"docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"fieldId": "2",
"fieldName": "name",
"height": int64(1),
"links": []map[string]any{},
},
{
"cid": "bafybeiekajrgheumrgamrc4mprmm66ulp2qr75sviowfcriuviggokydbm",
"collectionID": int64(1),
"delta": nil,
"docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"fieldId": "C",
"fieldName": nil,
"height": int64(2),
"links": []map[string]any{
{
"cid": "bafybeiggrv6gyhld2dbkspaxsenjejfhnk52pm4mlpyz2q6x4dlnaff2mu",
"name": "_head",
},
{
"cid": "bafybeiddpjl27ulw2yo4ohup6gr2wob3pwagqw2rbeaxxodv4ljelnu7ve",
"name": "age",
},
},
},
{
"cid": "bafybeiggrv6gyhld2dbkspaxsenjejfhnk52pm4mlpyz2q6x4dlnaff2mu",
"collectionID": int64(1),
"delta": nil,
"docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"fieldId": "C",
"fieldName": nil,
"height": int64(1),
"links": []map[string]any{
{
"cid": "bafybeieikx6l2xead2dzsa5wwy5irxced2eddyq23jkp4csf5igoob7diq",
"name": "age",
},
{
"cid": "bafybeiehcr3diremeja2ndk2osux647v5fc7s353h7pbvrnsagw4paugku",
"name": "name",
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}
171 changes: 171 additions & 0 deletions tests/integration/query/simple/with_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,174 @@ func TestQuerySimpleWithMultipleAliasedEmbeddedLatestCommit(t *testing.T) {

executeTestCase(t, test)
}

func TestQuery_WithAllCommitFields_NoError(t *testing.T) {
const docID = "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"

test := testUtils.TestCase{
Description: "Embedded commits query within object query with document ID",
Actions: []any{
testUtils.SchemaUpdate{
Schema: userCollectionGQLSchema,
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"Name": "John",
"Age": 21
}`,
},
testUtils.Request{
Request: `query {
Users {
Name
_docID
_version {
cid
collectionID
delta
docID
fieldId
fieldName
height
links {
cid
name
}
schemaVersionId
}
}
}`,
Results: []map[string]any{
{
"Name": "John",
"_docID": docID,
"_version": []map[string]any{
{
"cid": "bafybeib26cyuzbnf7uq3js5mykfveplsn4imo2fmf2jnnib6rrtnllv4pe",
"collectionID": int64(1),
"delta": nil,
"docID": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
"fieldId": "C",
"fieldName": nil,
"height": int64(1),
"links": []map[string]any{
{
"cid": "bafybeihkhgtdogxwqe2lkjqord5bzthfwwthyo3gu6iljfm5l7n7fkhpsq",
"name": "Age",
},
{
"cid": "bafybeico2g2tdkpo4i64ph6b5vgngn5zbxus4jxwav3bi2joieqicplfxi",
"name": "Name",
},
},
"schemaVersionId": "bafkreihuvcb7e7vy6ua3yrwbwnul3djqrtbhyuv3c4dqe4y3i2ssudzveu",
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

func TestQuery_WithAllCommitFieldsWithUpdate_NoError(t *testing.T) {
const docID = "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"

test := testUtils.TestCase{
Description: "Embedded commits query within object query with document ID",
Actions: []any{
testUtils.SchemaUpdate{
Schema: userCollectionGQLSchema,
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"Name": "John",
"Age": 21
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{"Age": 22}`,
},
testUtils.Request{
Request: `query {
Users {
Name
Age
_docID
_version {
cid
collectionID
delta
docID
fieldId
fieldName
height
links {
cid
name
}
schemaVersionId
}
}
}`,
Results: []map[string]any{
{
"Name": "John",
"Age": int64(22),
"_docID": docID,
"_version": []map[string]any{
{
"cid": "bafybeie23a5xsx4qyoffa3riij3kei5to54bb6gq7m4lftfjujaohkabwu",
"collectionID": int64(1),
"delta": nil,
"docID": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
"fieldId": "C",
"fieldName": nil,
"height": int64(2),
"links": []map[string]any{
{
"cid": "bafybeicixwhd4prbj2jfnkkc3a7wr2f5twppyhivg3kajoe7jal5cvrdza",
"name": "Age",
},
{
"cid": "bafybeib26cyuzbnf7uq3js5mykfveplsn4imo2fmf2jnnib6rrtnllv4pe",
"name": "_head",
},
},
"schemaVersionId": "bafkreihuvcb7e7vy6ua3yrwbwnul3djqrtbhyuv3c4dqe4y3i2ssudzveu",
},
{
"cid": "bafybeib26cyuzbnf7uq3js5mykfveplsn4imo2fmf2jnnib6rrtnllv4pe",
"collectionID": int64(1),
"delta": nil,
"docID": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
"fieldId": "C",
"fieldName": nil,
"height": int64(1),
"links": []map[string]any{
{
"cid": "bafybeihkhgtdogxwqe2lkjqord5bzthfwwthyo3gu6iljfm5l7n7fkhpsq",
"name": "Age",
},
{
"cid": "bafybeico2g2tdkpo4i64ph6b5vgngn5zbxus4jxwav3bi2joieqicplfxi",
"name": "Name",
},
},
"schemaVersionId": "bafkreihuvcb7e7vy6ua3yrwbwnul3djqrtbhyuv3c4dqe4y3i2ssudzveu",
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}
3 changes: 3 additions & 0 deletions tests/integration/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package tests

import (
"encoding/base64"
"encoding/json"
"testing"
"time"
Expand Down Expand Up @@ -116,6 +117,8 @@ func areResultsEqual(expected any, actual any) bool {
return areResultOptionsEqual(expectedVal, actual)
case immutable.Option[string]:
return areResultOptionsEqual(expectedVal, actual)
case []uint8:
return areResultsEqual(base64.StdEncoding.EncodeToString(expectedVal), actual)
case []int64:
return areResultArraysEqual(expectedVal, actual)
case []uint64:
Expand Down
Loading

0 comments on commit 31297f8

Please sign in to comment.