|
1 | 1 | using System.Collections.Generic;
|
| 2 | +using System.Text.Json; |
| 3 | +using System.Text.Json.Nodes; |
2 | 4 | using System.Threading.Tasks;
|
3 | 5 | using commercetools.Sdk.Api.Client;
|
4 | 6 | using commercetools.Sdk.Api.Models.Common;
|
5 | 7 | using commercetools.Sdk.Api.Models.Types;
|
| 8 | +using commercetools.Sdk.GraphQL.Api; |
6 | 9 | using Xunit;
|
7 | 10 | using static commercetools.Api.IntegrationTests.Type.TypeFixtures;
|
| 11 | +using static commercetools.Api.IntegrationTests.Cart.CartFixture; |
| 12 | +using CustomFieldsDraft = commercetools.Sdk.Api.Models.Types.CustomFieldsDraft; |
| 13 | +using FieldDefinition = commercetools.Sdk.Api.Models.Types.FieldDefinition; |
| 14 | +using FieldType = commercetools.Sdk.Api.Models.Types.FieldType; |
| 15 | +using LocalizedString = commercetools.Sdk.Api.Models.Common.LocalizedString; |
8 | 16 |
|
9 | 17 | namespace commercetools.Api.IntegrationTests.Type
|
10 | 18 | {
|
@@ -71,6 +79,80 @@ await WithType(
|
71 | 79 | });
|
72 | 80 | }
|
73 | 81 |
|
| 82 | + [Fact] |
| 83 | + public async Task CartWithCustomType() |
| 84 | + { |
| 85 | + var gqlClient = _client.GraphQLClient(); |
| 86 | + |
| 87 | + var key = $"QueryType-{TestingUtility.RandomString()}"; |
| 88 | + |
| 89 | + await WithType( |
| 90 | + _client, |
| 91 | + typeDraft => |
| 92 | + { |
| 93 | + var draft = DefaultTypeDraftWithKey(typeDraft, key); |
| 94 | + draft.FieldDefinitions = new List<IFieldDefinition>() |
| 95 | + { |
| 96 | + new FieldDefinition() |
| 97 | + { |
| 98 | + Type = new CustomFieldStringType() |
| 99 | + { |
| 100 | + }, |
| 101 | + Label = new LocalizedString() |
| 102 | + { |
| 103 | + {"en", "test-string"} |
| 104 | + }, |
| 105 | + Required = false, |
| 106 | + Name = "test-string" |
| 107 | + }, |
| 108 | + new FieldDefinition() |
| 109 | + { |
| 110 | + Type = new CustomFieldSetType() |
| 111 | + { |
| 112 | + ElementType = new CustomFieldStringType() |
| 113 | + }, |
| 114 | + Label = new LocalizedString() |
| 115 | + { |
| 116 | + {"en", "test-set"} |
| 117 | + }, |
| 118 | + Required = false, |
| 119 | + Name = "test-set" |
| 120 | + } |
| 121 | + }; |
| 122 | + return draft; |
| 123 | + }, |
| 124 | + async type => |
| 125 | + { |
| 126 | + await WithCart(_client, cartDraft => |
| 127 | + { |
| 128 | + var draft = DefaultCartDraft(cartDraft); |
| 129 | + draft.Custom = new CustomFieldsDraft() |
| 130 | + { |
| 131 | + Type = new TypeResourceIdentifier() { Key = type.Key }, |
| 132 | + Fields = new FieldContainer() |
| 133 | + { |
| 134 | + { "test-set", new List<string>() |
| 135 | + { |
| 136 | + "abc", |
| 137 | + "def" |
| 138 | + } |
| 139 | + }, |
| 140 | + { "test-string", "foo" |
| 141 | + } |
| 142 | + } |
| 143 | + }; |
| 144 | + return draft; |
| 145 | + }, async cart => |
| 146 | + { |
| 147 | + var cartId = cart.Id; |
| 148 | + var t = await gqlClient.Query(o => o.Cart(id: cartId, selector: cart => new { Custom = cart.Custom(custom => new { Field = custom.CustomFieldsRaw(selector: field => field.Value) })})); |
| 149 | + Assert.Equal("abc", t.Data.Custom.Field[0].Deserialize<List<string>>()[0]); |
| 150 | + Assert.Equal("def", t.Data.Custom.Field[0].Deserialize<List<string>>()[1]); |
| 151 | + Assert.Equal("foo", t.Data.Custom.Field[1].ToString()); |
| 152 | + }); |
| 153 | + }); |
| 154 | + } |
| 155 | + |
74 | 156 | [Fact]
|
75 | 157 | public async Task UpdateTypeByIdChangeDescription()
|
76 | 158 | {
|
|
0 commit comments