-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
adding or removing values from or into an array and then calling get
returns _Map<String, dynamic>
#834
Comments
Thanks for opening this issue!
|
I just find it out while writing tests for I have written all the tests to make sure that will not happen again. we just need to fix it. I will open a new PR to attempt to fix this after this PR #805 is merged. Testsgroup('Array', () {
const keyArray = 'array';
late ParseObject dietPlansObject;
setUp(() {
dietPlansObject = ParseObject("Diet_Plans", client: client);
});
test(
'adding values using setAdd() and then calling get(keyArray) '
'should return Instance of Iterable that contains all the added values ',
() {
// act
dietPlansObject.setAdd(keyArray, 1);
dietPlansObject.setAdd(keyArray, 2);
dietPlansObject.setAdd(keyArray, 1);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 1],
),
isTrue,
);
});
test(
'adding values using setAddAll() and then calling get(keyArray) '
'should return Instance of Iterable that contains all the added values',
() {
// act
dietPlansObject.setAddAll(keyArray, [1, 2, 1]);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 1],
),
isTrue,
);
});
test(
'adding values using setAddUnique() and then calling get(keyArray) '
'should return Instance of Iterable that contains all the added values'
' with out any duplication in the values', () {
// act
dietPlansObject.setAddUnique(keyArray, 1);
dietPlansObject.setAddUnique(keyArray, 2);
dietPlansObject.setAddUnique(keyArray, 1);
dietPlansObject.setAddUnique(keyArray, 3);
dietPlansObject.setAddUnique(keyArray, 1);
dietPlansObject.setAddUnique(keyArray, 4);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 3, 4],
),
isTrue,
);
});
test(
'adding values using setAddAllUnique() and then calling get(keyArray) '
'should return Instance of Iterable that contains all the added values'
' with out any duplication in the values', () {
// act
dietPlansObject.setAddAllUnique(keyArray, [1, 2, 1, 3, 1, 4, 1]);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 3, 4],
),
isTrue,
);
});
test(
'removing values using setRemove() and then calling get(keyArray) '
'should return Instance of Iterable that NOT contains the removed values',
() {
// arrange
final resultFromServer = {
"objectId": "O6BHlwV48Z",
"createdAt": "2023-02-26T13:23:03.073Z",
"updatedAt": "2023-03-01T03:38:16.390Z",
keyArray: [1, 2, 3, 4],
};
dietPlansObject = ParseObject('Diet_Plans')
..fromJson(
resultFromServer,
);
// act
dietPlansObject.setRemove(keyArray, 4);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 3],
),
isTrue,
);
});
test(
'removing values using setRemoveAll() and then calling get(keyArray) '
'should return Instance of Iterable that NOT contains the removed values',
() {
// arrange
final resultFromServer = {
"objectId": "O6BHlwV48Z",
"createdAt": "2023-02-26T13:23:03.073Z",
"updatedAt": "2023-03-01T03:38:16.390Z",
keyArray: [1, 2, 3, 4],
};
dietPlansObject = ParseObject('Diet_Plans')
..fromJson(
resultFromServer,
);
// act
dietPlansObject.setRemoveAll(keyArray, [3, 4]);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2],
),
isTrue,
);
});
test(
'the array should not been affected by removing non existent '
'values using setRemove()', () {
// arrange
final resultFromServer = {
"objectId": "O6BHlwV48Z",
"createdAt": "2023-02-26T13:23:03.073Z",
"updatedAt": "2023-03-01T03:38:16.390Z",
keyArray: [1, 2, 3, 4],
};
dietPlansObject = ParseObject('Diet_Plans')
..fromJson(
resultFromServer,
);
// act
dietPlansObject.setRemove(keyArray, 15);
dietPlansObject.setRemove(keyArray, 16);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 3, 4],
),
isTrue,
);
});
test(
'the array should not been affected by removing non existent '
'values using setRemoveAll()', () {
// arrange
final resultFromServer = {
"objectId": "O6BHlwV48Z",
"createdAt": "2023-02-26T13:23:03.073Z",
"updatedAt": "2023-03-01T03:38:16.390Z",
keyArray: [1, 2, 3, 4],
};
dietPlansObject = ParseObject('Diet_Plans')
..fromJson(
resultFromServer,
);
// act
dietPlansObject.setRemoveAll(keyArray, [15, 16]);
// assert
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2, 3, 4],
),
isTrue,
);
});
test(
'adding to an array and then removing from it should result in error '
'the user can not add and remove in the same time', () {
// act
dietPlansObject.setAdd(keyArray, 1);
dietPlansObject.setAdd(keyArray, 2);
// assert
expect(
() => dietPlansObject.setRemove(keyArray, 2),
throwsA(isA<String>()),
);
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2],
),
isTrue,
);
});
test(
'removing from an array and then adding to it should result in error '
'the user can not remove and add in the same time', () {
// arrange
final resultFromServer = {
"objectId": "O6BHlwV48Z",
"createdAt": "2023-02-26T13:23:03.073Z",
"updatedAt": "2023-03-01T03:38:16.390Z",
keyArray: [1, 2, 3, 4],
};
dietPlansObject = ParseObject('Diet_Plans')
..fromJson(
resultFromServer,
);
// act
dietPlansObject.setRemove(keyArray, 4);
dietPlansObject.setRemove(keyArray, 3);
// assert
expect(
() => dietPlansObject.setAdd(keyArray, 5),
throwsA(isA<String>()),
);
final array = dietPlansObject.get(keyArray);
expect(array, isA<Iterable>());
expect(
DeepCollectionEquality.unordered().equals(
array,
[1, 2],
),
isTrue,
);
});
}); |
Thanks @Nidal-Bakir; you've been quite active recently, would you be interested in joining the Parse Flutter SDK review team? You'll get notified when there's a review request for PRs. |
Thank you for the offer, @mtrezza I would be honored to join the Parse Flutter SDK review team and contribute to the development of the SDK. |
Great, you'll receive an invitation shortly |
Fix via #860 |
New Issue Checklist
Issue Description
Adding or removing values from or into an array using (
setAdd
,setAddAll
,setAddUnique
,setAddAllUnique
,setRemove
,setRemoveAll
) inParseObject
and then callingget
returns_Map<String, dynamic>
related to: #696, #842
Steps to reproduce
ParseObject
setAdd
function for exampleget("key")
get("key")
isMap
which is not expectedcode snippet:
Actual Outcome
_Map<String, dynamic>
Expected Outcome
An
Iterable
that contains all the added values and does not contain the removed onesEnvironment
Parse Flutter SDK
3.1.15
any
Server
any
Logs
The text was updated successfully, but these errors were encountered: