-
-
Notifications
You must be signed in to change notification settings - Fork 207
feat: Add include
option to getObject
and fetch
#798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mtrezza
merged 13 commits into
parse-community:master
from
mbfakourii:support_include_in_getobject_and_fetch
Dec 22, 2022
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
33cc2b8
added include in getObject and fetch and added test
mbfakourii 58dc003
Merge branch 'master' into support_include_in_getobject_and_fetch
mbfakourii 150ad24
Update packages/dart/test/parse_object_test.dart
mbfakourii 9374ba2
Update packages/dart/test/parse_object_test.dart
mbfakourii d8cbce2
change test.parse to example.com
mbfakourii 9a0c3f4
remove protected for use in external use
mbfakourii b922813
fix ParseInstallation timeZone missing
mbfakourii 94c0a9a
revert to back
mbfakourii 0d95694
remove unnecessary import
mbfakourii 0aea5ff
Solving the problem of tests and reformatting
mbfakourii 8144dc0
dart formatting
mbfakourii aa53063
bumped version and add Changes in CHANGELOG.md
mbfakourii 2977b19
Update packages/dart/CHANGELOG.md
mbfakourii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,185 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:parse_server_sdk/parse_server_sdk.dart'; | ||
import 'package:test/test.dart'; | ||
import 'parse_query_test.mocks.dart'; | ||
|
||
@GenerateMocks([ParseClient]) | ||
void main() { | ||
group('parseObject', () { | ||
late MockParseClient client; | ||
setUp(() async { | ||
client = MockParseClient(); | ||
|
||
await Parse().initialize( | ||
'appId', | ||
'https://example.com', | ||
debug: true, | ||
// to prevent automatic detection | ||
fileDirectory: 'someDirectory', | ||
// to prevent automatic detection | ||
appName: 'appName', | ||
// to prevent automatic detection | ||
appPackageName: 'somePackageName', | ||
// to prevent automatic detection | ||
appVersion: 'someAppVersion', | ||
); | ||
}); | ||
|
||
test('should return expectedIncludeResult json when use fetch', () async { | ||
// arrange | ||
ParseObject myUserObject = ParseObject("MyUser", client: client); | ||
myUserObject.objectId = "Mn1iJTkWTE"; | ||
|
||
var desiredOutput = { | ||
"results": [ | ||
{ | ||
"objectId": "Mn1iJTkWTE", | ||
"phone": "+12025550463", | ||
"createdAt": "2022-09-04T13:35:20.883Z", | ||
"updatedAt": "2022-11-14T10:55:56.202Z", | ||
"img": { | ||
"objectId": "8nGrLj3Mvk", | ||
"size": "67663", | ||
"mime": "image/jpg", | ||
"file": { | ||
"__type": "File", | ||
"name": "dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
"url": | ||
"http://ip:port/api/files/myapp/dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
}, | ||
"createdAt": "2022-11-14T10:55:56.025Z", | ||
"updatedAt": "2022-11-14T10:55:56.025Z", | ||
"__type": "Object", | ||
"className": "MyFile", | ||
}, | ||
} | ||
] | ||
}; | ||
|
||
when(client.get( | ||
any, | ||
options: anyNamed("options"), | ||
onReceiveProgress: anyNamed("onReceiveProgress"), | ||
)).thenAnswer((_) async => ParseNetworkResponse( | ||
statusCode: 200, data: jsonEncode(desiredOutput))); | ||
|
||
// act | ||
ParseObject parseObject = await myUserObject.fetch(include: ["img"]); | ||
|
||
var objectDesiredOutput = { | ||
"className": "MyFile", | ||
"objectId": "8nGrLj3Mvk", | ||
"createdAt": "2022-11-14T10:55:56.025Z", | ||
"updatedAt": "2022-11-14T10:55:56.025Z", | ||
"size": "67663", | ||
"mime": "image/jpg", | ||
"file": { | ||
"__type": "File", | ||
"name": "dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
"url": | ||
"http://ip:port/api/files/myapp/dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
}, | ||
}; | ||
var objectJsonDesiredOutput = jsonEncode(objectDesiredOutput); | ||
|
||
final Uri result = Uri.parse(verify(client.get( | ||
captureAny, | ||
options: anyNamed("options"), | ||
onReceiveProgress: anyNamed("onReceiveProgress"), | ||
)).captured.single); | ||
|
||
// assert | ||
expect( | ||
jsonEncode( | ||
parseEncode(parseObject.get<ParseObject>('img'), full: true)), | ||
objectJsonDesiredOutput); | ||
expect(parseObject['img'].objectId, "8nGrLj3Mvk"); | ||
|
||
expect(Uri.decodeComponent(result.path), | ||
'/classes/MyUser/Mn1iJTkWTE?include=img'); | ||
}); | ||
|
||
test('should return expectedIncludeResult json when use getObject', | ||
() async { | ||
// arrange | ||
ParseObject myUserObject = ParseObject("MyUser", client: client); | ||
myUserObject.objectId = "Mn1iJTkWTE"; | ||
|
||
var desiredOutput = { | ||
"results": [ | ||
{ | ||
"objectId": "Mn1iJTkWTE", | ||
"phone": "+12025550463", | ||
"createdAt": "2022-09-04T13:35:20.883Z", | ||
"updatedAt": "2022-11-14T10:55:56.202Z", | ||
"img": { | ||
"objectId": "8nGrLj3Mvk", | ||
"size": "67663", | ||
"mime": "image/jpg", | ||
"file": { | ||
"__type": "File", | ||
"name": "dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
"url": | ||
"http://ip:port/api/files/myapp/dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
}, | ||
"createdAt": "2022-11-14T10:55:56.025Z", | ||
"updatedAt": "2022-11-14T10:55:56.025Z", | ||
"__type": "Object", | ||
"className": "MyFile", | ||
}, | ||
} | ||
] | ||
}; | ||
|
||
when(client.get( | ||
any, | ||
options: anyNamed("options"), | ||
onReceiveProgress: anyNamed("onReceiveProgress"), | ||
)).thenAnswer((_) async => ParseNetworkResponse( | ||
statusCode: 200, data: jsonEncode(desiredOutput))); | ||
|
||
// act | ||
ParseResponse response = | ||
await myUserObject.getObject("Mn1iJTkWTE", include: ["img"]); | ||
|
||
ParseObject parseObject = response.results?.first; | ||
|
||
var objectDesiredOutput = { | ||
"className": "MyFile", | ||
"objectId": "8nGrLj3Mvk", | ||
"createdAt": "2022-11-14T10:55:56.025Z", | ||
"updatedAt": "2022-11-14T10:55:56.025Z", | ||
"size": "67663", | ||
"mime": "image/jpg", | ||
"file": { | ||
"__type": "File", | ||
"name": "dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
"url": | ||
"http://ip:port/api/files/myapp/dc7320ee9146ee19aed8997722fd4e3c.bin", | ||
}, | ||
}; | ||
var objectJsonDesiredOutput = jsonEncode(objectDesiredOutput); | ||
|
||
final Uri result = Uri.parse(verify(client.get( | ||
captureAny, | ||
options: anyNamed("options"), | ||
onReceiveProgress: anyNamed("onReceiveProgress"), | ||
)).captured.single); | ||
|
||
// assert | ||
expect(response.results?.first, isA<ParseObject>()); | ||
|
||
expect( | ||
jsonEncode( | ||
parseEncode(parseObject.get<ParseObject>('img'), full: true)), | ||
objectJsonDesiredOutput); | ||
expect(parseObject['img'].objectId, "8nGrLj3Mvk"); | ||
|
||
expect(Uri.decodeComponent(result.path), | ||
'/classes/MyUser/Mn1iJTkWTE?include=img'); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.