Skip to content

Commit d665acd

Browse files
committed
chore(datastore): improve custom primary key integration tests (#2000)
1 parent 80cde90 commit d665acd

File tree

4 files changed

+155
-94
lines changed

4 files changed

+155
-94
lines changed

packages/amplify_datastore/example/integration_test/separate_integration_tests/cpk_has_many_bidirectional_implicit_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ void main() {
5353
.eq(associatedModel.name),
5454
)
5555
.toList();
56+
var associatedModelNeQueryPredicates = associatedModels
57+
.map(
58+
(associatedModel) =>
59+
CpkHasManyChildBidirectionalImplicit.MODEL_IDENTIFIER.ne(
60+
associatedModel.modelIdentifier,
61+
),
62+
)
63+
.toList();
5664

5765
testRootAndAssociatedModelsRelationship(
5866
modelProvider: ModelProvider.instance,
@@ -65,9 +73,11 @@ void main() {
6573
associatedModelQueryIdentifier:
6674
CpkHasManyChildBidirectionalImplicit.MODEL_IDENTIFIER,
6775
associatedModelQueryPredicates: associatedModelQueryPredicates,
76+
associatedModelQueryNePredicates: associatedModelNeQueryPredicates,
6877
supportCascadeDelete: true,
6978
enableCloudSync: enableCloudSync,
7079
verifyBelongsToPopulating: true,
80+
testNeOperationOnBelongsTo: true,
7181
);
7282
});
7383
}

packages/amplify_datastore/example/integration_test/separate_integration_tests/cpk_one_to_one_bidirectional_implicit_belongs_to_custom_id_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ void main() {
5757
associatedModels.first.name,
5858
),
5959
];
60+
var associatedModelNeQueryPredicates = [
61+
CpkOneToOneBidirectionalChildImplicitCD.NAME.ne(
62+
associatedModels.first.name,
63+
),
64+
];
6065

6166
testRootAndAssociatedModelsRelationship(
6267
modelProvider: ModelProvider.instance,
@@ -71,7 +76,9 @@ void main() {
7176
supportCascadeDelete: true,
7277
enableCloudSync: enableCloudSync,
7378
associatedModelQueryPredicates: associatedModelQueryPredicates,
79+
associatedModelQueryNePredicates: associatedModelNeQueryPredicates,
7480
verifyBelongsToPopulating: true,
81+
testNeOperationOnBelongsTo: true,
7582
);
7683
});
7784
}

packages/amplify_datastore/example/integration_test/utils/test_cloud_synced_model_operation.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ void testRootAndAssociatedModelsRelationship<R extends Model, A extends Model>({
180180
required List<A> associatedModels,
181181
required QueryModelIdentifier associatedModelQueryIdentifier,
182182
List<QueryPredicate>? associatedModelQueryPredicates,
183+
List<QueryPredicate>? associatedModelQueryNePredicates,
183184
bool enableCloudSync = false,
184185
bool supportCascadeDelete = false,
185186
bool verifyBelongsToPopulating = false,
187+
bool testNeOperationOnBelongsTo = false,
186188
}) {
187189
late Future<List<SubscriptionEvent<R>>> observedRootModelsEvents;
188190
late Future<List<SubscriptionEvent<A>>> observedAssociatedModelsEvents;
@@ -275,6 +277,20 @@ void testRootAndAssociatedModelsRelationship<R extends Model, A extends Model>({
275277
});
276278
}
277279

280+
if (testNeOperationOnBelongsTo && associatedModelQueryNePredicates != null) {
281+
testWidgets(
282+
'query associated model with ne operator on model identifier should exclude the model from results',
283+
(WidgetTester tester) async {
284+
associatedModels.asMap().forEach((index, associatedModel) async {
285+
final expectedModels = await Amplify.DataStore.query(
286+
associatedModelType,
287+
where: associatedModelQueryNePredicates[index],
288+
);
289+
expectSync(expectedModels, isNot(contains(associatedModel)));
290+
});
291+
});
292+
}
293+
278294
testWidgets('observed root models creation events',
279295
(WidgetTester tester) async {
280296
var events = await observedRootModelsEvents;

packages/amplify_datastore/example/tool/schema.graphql

Lines changed: 122 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
input AMPLIFY {
22
globalAuthRule: AuthRule = { allow: public }
33
}
4+
45
type Blog @model {
56
id: ID!
67
name: String!
@@ -217,103 +218,130 @@ type MultiRelatedRegistration @model {
217218
attendee: MultiRelatedAttendee! @belongsTo(fields: ["attendeeId"])
218219
}
219220

220-
type CPKInventory @model {
221+
type CpkInventory @model {
221222
productId: ID! @primaryKey(sortKeyFields: ["productName", "warehouseId"])
222223
productName: String!
223224
warehouseId: String!
224225
description: String
225226
}
226227

227-
# type CPKHasOneParent @model {
228-
# id: ID! @primaryKey(sortKeyFields: ["name"])
229-
# name: String!
230-
# implicitChild: CPKHasOneChild @hasOne
231-
# explicitChildId: ID
232-
# explicitChildName: String
233-
# explicitChild: CPKHasOneChild
234-
# @hasOne(fields: ["explicitChildId", "explicitChildName"])
235-
# }
236-
237-
# type CPKHasOneChild @model {
238-
# id: ID! @primaryKey(sortKeyFields: ["name"])
239-
# name: String!
240-
# }
241-
242-
# type CPKBelongsToParent @model {
243-
# id: ID! @primaryKey(sortKeyFields: ["name"])
244-
# name: String!
245-
# implicitChild: CPKBelongsToChildImplicit @hasOne
246-
# explicitChild: CPKBelongsToChildExplicit @hasOne
247-
# }
248-
249-
# type CPKBelongsToChildImplicit @model {
250-
# id: ID! @primaryKey(sortKeyFields: ["name"])
251-
# name: String!
252-
# parent: CPKHasOneParent @belongsTo
253-
# }
254-
255-
# type CPKBelongsToChildExplicit @model {
256-
# id: ID! @primaryKey(sortKeyFields: ["name"])
257-
# name: String!
258-
# parentId: ID!
259-
# parentName: String!
260-
# parent: CPKHasOneParent @belongsTo(fields: ["projectId", "projectName"])
261-
# }
262-
263-
# type CPKHasManyParent @model {
264-
# id: ID! @primaryKey(sortKeyFields: ["title"])
265-
# title: String!
266-
# implicitChildren: [CPKHasManyChildImplicit] @hasMany
267-
# explicitChildren: [CPKHasManyChildExplicit]
268-
# @hasMany(indexName: "byCPKHasManyParent", fields: ["id"])
269-
# }
270-
271-
# type CPKHasManyChildImplicit @model {
272-
# id: ID! @primaryKey(sortKeyFields: ["content"])
273-
# content: String!
274-
# }
275-
276-
# type CPKHasManyChildExplicit @model {
277-
# id: ID! @primaryKey(sortKeyFields: ["content"])
278-
# content: String!
279-
# hasManyParentId: ID
280-
# @index(name: "byCPKHasManyParent", sortKeyFields: ["content"])
281-
# }
282-
283-
# type CPKHasManyParentBidirectionalImplicit @model {
284-
# id: ID! @primaryKey(sortKeyFields: ["title"])
285-
# title: String!
286-
# cpkHasManyImplicitChildren: [CPKHasManyChildImplicit] @hasMany
287-
# }
288-
289-
# type CPKHasManyChildImplicit @model {
290-
# id: ID! @primaryKey(sortKeyFields: ["content"])
291-
# content: String!
292-
# hasManyParent: CPKHasManyParentBidirectionalImplicit @belongsTo
293-
# }
294-
295-
# type CPKHasManyParentBidirectionalExplicit @model {
296-
# id: ID! @primaryKey(sortKeyFields: ["title"])
297-
# title: String!
298-
# cpkHasManyExplicitChildren: [CPKHasManyChildExplicit] @hasMany
299-
# }
300-
301-
# type CPKHasManyChildExplicit @model {
302-
# id: ID! @primaryKey(sortKeyFields: ["content"])
303-
# content: String!
304-
# hasManyParentId: ID @index(name: "byCPKHasManyParentBidirectionalExplicit", sortKeyFields: ["content"])
305-
# hasManyParent: CPKHasManyParentBidirectionalImplicit @belongsTo(fields: ["hasManyParentID"])
306-
# }
307-
308-
# type CPKManyToManyPost @model {
309-
# id: ID!
310-
# title: String!
311-
# content: String
312-
# tags: [CPKManyToManyTag] @manyToMany(relationName: "CPKPostTags")
313-
# }
314-
315-
# type CPKManyToManyTag @model {
316-
# id: ID! @primaryKey(sortKeyFields: ["label"])
317-
# label: String!
318-
# posts: [CPKManyToManyPost] @manyToMany(relationName: "CPKPostTags")
319-
# }
228+
type CpkHasOneUnidirectionalParent @model {
229+
id: ID! @primaryKey(sortKeyFields: ["name"])
230+
name: String!
231+
implicitChild: CpkHasOneUnidirectionalChild @hasOne
232+
explicitChildID: ID
233+
explicitChildName: String
234+
explicitChild: CpkHasOneUnidirectionalChild
235+
@hasOne(fields: ["explicitChildID", "explicitChildName"])
236+
}
237+
238+
type CpkHasOneUnidirectionalChild @model {
239+
id: ID! @primaryKey(sortKeyFields: ["name"])
240+
name: String!
241+
}
242+
243+
type CpkOneToOneBidirectionalParentCD @model {
244+
customId: ID! @primaryKey(sortKeyFields: ["name"])
245+
name: String!
246+
implicitChild: CpkOneToOneBidirectionalChildImplicitCD @hasOne
247+
explicitChild: CpkOneToOneBidirectionalChildExplicitCD @hasOne
248+
}
249+
250+
type CpkOneToOneBidirectionalChildImplicitCD @model {
251+
id: ID! @primaryKey(sortKeyFields: ["name"])
252+
name: String!
253+
belongsToParent: CpkOneToOneBidirectionalParentCD @belongsTo
254+
}
255+
256+
type CpkOneToOneBidirectionalChildExplicitCD @model {
257+
id: ID! @primaryKey(sortKeyFields: ["name"])
258+
name: String!
259+
belongsToParentID: ID
260+
belongsToParentName: String
261+
belongsToParent: CpkOneToOneBidirectionalParentCD
262+
@belongsTo(fields: ["belongsToParentID", "belongsToParentName"])
263+
}
264+
265+
type CpkOneToOneBidirectionalParentID @model {
266+
id: ID! @primaryKey(sortKeyFields: ["name"])
267+
name: String!
268+
implicitChild: CpkOneToOneBidirectionalChildImplicitID @hasOne
269+
explicitChild: CpkOneToOneBidirectionalChildExplicitID @hasOne
270+
}
271+
272+
type CpkOneToOneBidirectionalChildImplicitID @model {
273+
id: ID! @primaryKey(sortKeyFields: ["name"])
274+
name: String!
275+
belongsToParent: CpkOneToOneBidirectionalParentID @belongsTo
276+
}
277+
278+
type CpkOneToOneBidirectionalChildExplicitID @model {
279+
id: ID! @primaryKey(sortKeyFields: ["name"])
280+
name: String!
281+
belongsToParentID: ID
282+
belongsToParentName: String
283+
belongsToParent: CpkOneToOneBidirectionalParentID
284+
@belongsTo(fields: ["belongsToParentID", "belongsToParentName"])
285+
}
286+
287+
type CpkHasManyUnidirectionalParent @model {
288+
id: ID! @primaryKey(sortKeyFields: ["name"])
289+
name: String!
290+
implicitChildren: [CpkHasManyUnidirectionalChildImplicit] @hasMany
291+
explicitChildren: [CpkHasManyUnidirectionalChildExplicit]
292+
@hasMany(indexName: "byHasManyParentCpk", fields: ["id", "name"])
293+
}
294+
295+
type CpkHasManyUnidirectionalChildImplicit @model {
296+
id: ID! @primaryKey(sortKeyFields: ["name"])
297+
name: String!
298+
}
299+
300+
type CpkHasManyUnidirectionalChildExplicit @model {
301+
id: ID! @primaryKey(sortKeyFields: ["name"])
302+
name: String!
303+
hasManyParentID: ID!
304+
@index(name: "byHasManyParentCpk", sortKeyFields: ["hasManyParentName"])
305+
hasManyParentName: String!
306+
}
307+
308+
type CpkHasManyParentBidirectionalImplicit @model {
309+
id: ID! @primaryKey(sortKeyFields: ["name"])
310+
name: String!
311+
bidirectionalImplicitChildren: [CpkHasManyChildBidirectionalImplicit] @hasMany
312+
}
313+
314+
type CpkHasManyChildBidirectionalImplicit @model {
315+
id: ID! @primaryKey(sortKeyFields: ["name"])
316+
name: String!
317+
hasManyParent: CpkHasManyParentBidirectionalImplicit @belongsTo
318+
}
319+
320+
type CpkHasManyParentBidirectionalExplicit @model {
321+
id: ID! @primaryKey(sortKeyFields: ["name"])
322+
name: String!
323+
bidirectionalExplicitChildren: [CpkHasManyChildBidirectionalExplicit]
324+
@hasMany(indexName: "byHasManyParent", fields: ["id", "name"])
325+
}
326+
327+
type CpkHasManyChildBidirectionalExplicit @model {
328+
id: ID! @primaryKey(sortKeyFields: ["name"])
329+
name: String!
330+
hasManyParentID: ID!
331+
@index(name: "byHasManyParent", sortKeyFields: ["hasManyParentName"])
332+
hasManyParentName: String!
333+
hasManyParent: CpkHasManyParentBidirectionalExplicit
334+
@belongsTo(fields: ["hasManyParentID", "hasManyParentName"])
335+
}
336+
337+
type CpkManyToManyPost @model {
338+
id: ID!
339+
title: String!
340+
tags: [CpkManyToManyTag] @manyToMany(relationName: "CpkPostTags")
341+
}
342+
343+
type CpkManyToManyTag @model {
344+
id: ID! @primaryKey(sortKeyFields: ["label"])
345+
label: String!
346+
posts: [CpkManyToManyPost] @manyToMany(relationName: "CpkPostTags")
347+
}

0 commit comments

Comments
 (0)