idExistsInService function
Returns an AngelMatcher that verifies that an item with the given idField
exists in the service at servicePath
, without throwing a 404
or returning null
.
Implementation
AngelMatcher idExistsInService(String servicePath,
{String idField = 'id', String? description}) {
return predicateWithAngel(
(key, item, app) async {
try {
var result = await app.findService(servicePath)?.read(item);
return result != null;
} on AngelHttpException catch (e) {
if (e.statusCode == 404) {
return false;
} else {
rethrow;
}
}
},
description ?? 'exists in service $servicePath',
);
}