-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: fetching trait entities via graphql would not populate traite…
…ntity fields that have a dot in their identifier
- Loading branch information
1 parent
6ae619d
commit cf70909
Showing
2 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
backend/Tests/Integration/GraphQL/TraitEntityWithDotAttributeIdentifierTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using NUnit.Framework; | ||
using Omnikeeper.Base.Entity; | ||
using Omnikeeper.Base.Model; | ||
using System.Threading.Tasks; | ||
using Tests.Integration.GraphQL.Base; | ||
|
||
namespace Tests.Integration.GraphQL | ||
{ | ||
class TraitEntityWithDotAttributeIdentifierTest : QueryTestBase | ||
{ | ||
[Test] | ||
public async Task TestBasics() | ||
{ | ||
var userInDatabase = await SetupDefaultUser(); | ||
var (layerOkConfig, _) = await GetService<ILayerModel>().CreateLayerIfNotExists("__okconfig", ModelContextBuilder.BuildImmediate()); | ||
var (layer1, _) = await GetService<ILayerModel>().CreateLayerIfNotExists("layer_1", ModelContextBuilder.BuildImmediate()); | ||
var user = new AuthenticatedInternalUser(userInDatabase); | ||
|
||
// force rebuild graphql schema | ||
await ReinitSchema(); | ||
|
||
string mutationCreateTrait = @" | ||
mutation { | ||
manage_upsertRecursiveTrait( | ||
trait: { | ||
id: ""test_trait_a"" | ||
requiredAttributes: [ | ||
{ | ||
identifier: ""test.id"" | ||
template: { | ||
name: ""test_trait_a.id"" | ||
type: TEXT | ||
isID: true | ||
isArray: false | ||
valueConstraints: [] | ||
} | ||
} | ||
] | ||
optionalAttributes: [] | ||
optionalRelations: [], | ||
requiredTraits: [] | ||
} | ||
) { | ||
id | ||
} | ||
} | ||
"; | ||
var expected1 = @" | ||
{ | ||
""manage_upsertRecursiveTrait"": | ||
{ | ||
""id"": ""test_trait_a"" | ||
} | ||
}"; | ||
AssertQuerySuccess(mutationCreateTrait, expected1, user); | ||
|
||
// force rebuild graphql schema | ||
await ReinitSchema(); | ||
|
||
var queryTestTraitA = @" | ||
{ | ||
traitEntities(layers: [""layer_1""]) { | ||
test_trait_a { | ||
all { | ||
entity { | ||
test__id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"; | ||
var expected2 = @" | ||
{ | ||
""traitEntities"": { | ||
""test_trait_a"": { | ||
""all"": [] | ||
} | ||
} | ||
} | ||
"; | ||
AssertQuerySuccess(queryTestTraitA, expected2, user); | ||
|
||
// NOTE the double underscore intstead of a dot in the query | ||
var mutationInsert = @" | ||
mutation { | ||
insertNew_test_trait_a( | ||
layers: [""layer_1""] | ||
writeLayer: ""layer_1"" | ||
ciName: ""Entity 1"" | ||
input: { test__id: ""entity_1"" } | ||
) { | ||
entity { test__id } | ||
} | ||
} | ||
"; | ||
|
||
var expected3 = @" | ||
{ | ||
""insertNew_test_trait_a"": { | ||
""entity"": { | ||
""test__id"": ""entity_1"" | ||
} | ||
} | ||
} | ||
"; | ||
AssertQuerySuccess(mutationInsert, expected3, user); | ||
|
||
|
||
var expected4 = @" | ||
{ | ||
""traitEntities"": { | ||
""test_trait_a"": { | ||
""all"": [ | ||
{ | ||
""entity"": { | ||
""test__id"": ""entity_1"" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
"; | ||
AssertQuerySuccess(queryTestTraitA, expected4, user); | ||
} | ||
} | ||
} |