Comments (10)
I could be wrong, but I think this test may be incorrectly written:
func testSelectKeys() {
let query = GameScore.query()
XCTAssertNil(query.keys)
var query2 = GameScore.query().select("yolo")
XCTAssertEqual(query2.keys?.count, 1)
XCTAssertEqual(query2.keys?.first, "yolo")
query2 = query2.select("yolo", "wow")
XCTAssertEqual(query2.keys?.count, 2)
XCTAssertEqual(query2.keys, ["yolo", "wow"])
query2 = query2.select(["yolo"])
XCTAssertEqual(query2.keys?.count, 1)
XCTAssertEqual(query2.keys, ["yolo"])
}
I would imagine it could be something like:
func testSelectKeys() {
/// Poorly assuming .select() is equally effective on .first() and .find()
let query = GameScore.query()
let results = try? query.first()
XCTAssertNotEqual(results?.updatedAt, nil)
let query2 = GameScore.query().select("score")
let results2 = try? query2.first()
XCTAssertEqual(results2?.createdAt, nil)
XCTAssertEqual(results2?.updatedAt, nil)
XCTAssertNotEqual(results2?.score, nil)
let query3 = GameScore.query().select(["score", "createdAt"])
let results3 = try? query3.first()
XCTAssertNotEqual(results3?.createdAt, nil)
XCTAssertEqual(results3?.updatedAt, nil)
XCTAssertNotEqual(results3?.score, nil)
}
from parse-swift.
What error are you getting when trying select?
from parse-swift.
I could be wrong, but I think this test may be incorrectly written:
The test looks okay from what I see. An improvement could be to check that the selected keys are encoded because if keys
is accidentally removed from CodingKeys then the current test would miss this while it should fail. The improved test would be similar to
Parse-Swift/Tests/ParseSwiftTests/ParseQueryTests.swift
Lines 595 to 619 in 65bfd41
let results2 = try? query2.first()
There's no need to actually perform the query as 1) you will need to mock the network (like some of the other tests) 2) Testing to see if the keys array is populated/encoded properly is good enough for a client side test since the Parse Server does the rest.
from parse-swift.
If you add an example in Playgrounds to https://github.com/parse-community/Parse-Swift/blob/main/ParseSwift.playground/Pages/2%20-%20Finding%20Objects.xcplaygroundpage/Contents.swift
I can take a look
from parse-swift.
I've tested this by adding to the playgrounds file I mentioned above and it seems to work fine.
struct GameScore: ParseObject {
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Int?
var oldScore: Int?
}
var score = GameScore()
score.score = 200
score.oldScore = 10
do {
try score.save()
} catch {
print(error)
}
let afterDate = Date().addingTimeInterval(-300)
var query = GameScore.query("score" > 100, "createdAt" > afterDate)
// Query first asynchronously (preferred way) - Performs work on background
// queue and returns to designated on designated callbackQueue.
// If no callbackQueue is specified it returns to main queue.
query.first { results in
switch results {
case .success(let score):
guard score.objectId != nil,
let createdAt = score.createdAt else { fatalError() }
assert(createdAt.timeIntervalSince1970 > afterDate.timeIntervalSince1970, "date should be ok")
print("Found score: \(score)")
case .failure(let error):
assertionFailure("Error querying: \(error)")
}
}
//The above outputs:
// Found score: GameScore ({"objectId":"oBdHL84zSZ9qCWXFrB4RkhR5AOJd0a5U","updatedAt":{"__type":"Date","iso":"2021-03-02T18:30:07.596Z"},"score":200,"createdAt":{"__type":"Date","iso":"2021-03-02T18:30:07.482Z"}})
let querySelect = query.select("score")
querySelect.first { results in
switch results {
case .success(let score):
guard score.objectId != nil,
let createdAt = score.createdAt else { fatalError() }
assert(createdAt.timeIntervalSince1970 > afterDate.timeIntervalSince1970, "date should be ok")
print("Found score using select: \(score)")
case .failure(let error):
assertionFailure("Error querying: \(error)")
}
}
//Outputs:
//Found score using select: GameScore ({"objectId":"oBdHL84zSZ9qCWXFrB4RkhR5AOJd0a5U","updatedAt":{"__type":"Date","iso":"2021-03-02T18:30:07.596Z"},"score":200,"createdAt":{"__type":"Date","iso":"2021-03-02T18:30:07.482Z"}})
In the last output, oldScore
is missing because it wasn't selected.
from parse-swift.
Note that if you add a property to the your type that isn't optional (added highestScore
):
struct GameScore: ParseObject {
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Int?
var oldScore: Int?
var highestScore: Int //New property
}
highestScore
must be one of the keys
selected or else the compiler can't decode GameScore
. This would be considered a user error, because you are telling the compiler that GameScore
requires a value for highestScore
from parse-swift.
There may be something up with this...
from parse-swift.
Thanks @cbaker6 Glad it's working! I can't seem to reproduce your results, so I'll play around and see if I'm bugging out.
What error are you getting when trying select?
No error, but I'm getting all the fields back.
An improvement could be to check that the selected keys are encoded because if keys is accidentally removed from CodingKeys then the current test would miss this while it should fail.
Agree.
EDIT: I'm using Parse-Swift 1.1.6 and Parse-Server 4.5.0.
from parse-swift.
Noting that this has been classified as a server-side bug as oppose to a Parse-Swift bug. Check the linked PR and issue for details.
from parse-swift.
The fix on the server side has been merged to the master. If you would like to use select
and and exclude
with the ParseSwift client, please use the latest master branch of the parse-server.
from parse-swift.
Related Issues (20)
- Remove duplicate docs HOT 4
- Allow implementations of ParseObjects to set their own className HOT 7
- Allow implementations of ParseObjects to set their own className HOT 4
- Nested ParseFile saves invalid data HOT 1
- Auto-reuse existing installation object when migrating from ObjC SDK HOT 7
- Add offline object saving HOT 26
- Delete installation is impossible HOT 7
- Parse.User save not dispatching back to callback queue when result is success HOT 5
- 📣 Contributors wanted! HOT 1
- Parse Analytics - Track App Opened HOT 1
- ParseConfig throwing Codable errors when type `Object` exists in Config. HOT 1
- Unable to parse the exact error from ParseError HOT 1
- Fatal error: Duplicate elements of type 'ParseFile' were found in a Set. This usually means either that the type violates Hashable's requirements, or that members of such a set were mutated after insertion HOT 1
- Does not support automatic/anonymous user HOT 1
- When is the next release? HOT 2
- Crash: Installation.current setter not thread safe HOT 1
- Request: Make backingStore optional rather than force unwrapped HOT 2
- PFFacebookUtils' has no member 'initializeFacebookWithLaunchOptions HOT 1
- Count return 0 HOT 1
- Does not build against visionOS target HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parse-swift.