-
Notifications
You must be signed in to change notification settings - Fork 37
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
BIT-162: Add sync API #22
Conversation
No New Or Fixed Issues Found |
/// | ||
let sizeName: String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fedemkr I wasn't sure what this field was used for based on the name. Is this a formatted string of the size (e.g. "5 MB") or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
🤔 A question, I see that you've added the let object: String?
to some models, we don't currently use that on the app, is it going to be useful for decoding or something or could we remove it?
🤔 Also I've marked several type
properties as never being nil
: I was wondering that maybe you marked it with ?
because perhaps is something needed for swift that I don't know, is it?
XCTAssertThrowsError( | ||
try subject.decode(Date.self, from: Data(#""2023-08-23""#.utf8)) | ||
) { error in | ||
XCTAssertTrue(error is DecodingError) | ||
guard case let .dataCorrupted(context) = error as? DecodingError else { | ||
return XCTFail("Expected error to be DecodingError.dataCorrupted") | ||
} | ||
XCTAssertEqual(context.debugDescription, "Unable to decode date with value '2023-08-23'") | ||
} | ||
|
||
XCTAssertThrowsError( | ||
try subject.decode(Date.self, from: Data(#""🔒""#.utf8)) | ||
) { error in | ||
XCTAssertTrue(error is DecodingError) | ||
guard case let .dataCorrupted(context) = error as? DecodingError else { | ||
return XCTFail("Expected error to be DecodingError.dataCorrupted") | ||
} | ||
XCTAssertEqual(context.debugDescription, "Unable to decode date with value '🔒'") | ||
} | ||
|
||
XCTAssertThrowsError( | ||
try subject.decode(Date.self, from: Data(#""date""#.utf8)) | ||
) { error in | ||
XCTAssertTrue(error is DecodingError) | ||
guard case let .dataCorrupted(context) = error as? DecodingError else { | ||
return XCTFail("Expected error to be DecodingError.dataCorrupted") | ||
} | ||
XCTAssertEqual(context.debugDescription, "Unable to decode date with value 'date'") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎨 Instead of repeating each time with different values what do you think on having something like:
XCTAssertThrowsError( | |
try subject.decode(Date.self, from: Data(#""2023-08-23""#.utf8)) | |
) { error in | |
XCTAssertTrue(error is DecodingError) | |
guard case let .dataCorrupted(context) = error as? DecodingError else { | |
return XCTFail("Expected error to be DecodingError.dataCorrupted") | |
} | |
XCTAssertEqual(context.debugDescription, "Unable to decode date with value '2023-08-23'") | |
} | |
XCTAssertThrowsError( | |
try subject.decode(Date.self, from: Data(#""🔒""#.utf8)) | |
) { error in | |
XCTAssertTrue(error is DecodingError) | |
guard case let .dataCorrupted(context) = error as? DecodingError else { | |
return XCTFail("Expected error to be DecodingError.dataCorrupted") | |
} | |
XCTAssertEqual(context.debugDescription, "Unable to decode date with value '🔒'") | |
} | |
XCTAssertThrowsError( | |
try subject.decode(Date.self, from: Data(#""date""#.utf8)) | |
) { error in | |
XCTAssertTrue(error is DecodingError) | |
guard case let .dataCorrupted(context) = error as? DecodingError else { | |
return XCTFail("Expected error to be DecodingError.dataCorrupted") | |
} | |
XCTAssertEqual(context.debugDescription, "Unable to decode date with value 'date'") | |
} | |
func expectFail(dateFrom value: String) { | |
XCTAssertThrowsError( | |
try subject.decode(Date.self, from: Data(value)) | |
) { error in | |
XCTAssertTrue(error is DecodingError) | |
guard case let .dataCorrupted(context) = error as? DecodingError else { | |
return XCTFail("Expected error to be DecodingError.dataCorrupted") | |
} | |
XCTAssertEqual(context.debugDescription, "Unable to decode date with value \(value)") | |
} | |
} | |
expectFail(dateFrom: #""2023-08-23""#.utf8) | |
expectFail(dateFrom: #""🔒""#.utf8) | |
expectFail(dateFrom: #""date""#.utf8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion! I'll update this.
/// | ||
let sizeName: String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// The size of the file. | ||
let size: Int? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Just in case, bear in mind that currently the size
is a string
because of some problems when converting the number and server side is allowing expecting an string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll convert it to a string.
/// Whether the user's email address should be hidden from recipients. | ||
let hideEmail: Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ This can be nil
, although it's transformed into false
when that happens in the process of creating the SendData
mobile object. I don't know if you plan to do that directly when decoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, I'll probably make it optional for now, but may either change that in the future or default it to false when transforming it into an app model.
let text: SendTextModel? | ||
|
||
/// The type of data in the send. | ||
let type: SendType? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ type
is never nil
/// The attachment's size. | ||
let size: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Same as with SendFileModel
/// Whether the user needs to be re-prompted for their master password prior to autofilling the | ||
/// cipher's password. | ||
let reprompt: CipherRepromptType? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ reprompt
is never nil
/// The type of the cipher. | ||
let type: CipherType? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ type
is never nil
/// The policy type. | ||
let type: PolicyType? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ type
is never nil
struct PolicyResponseModel: Codable, Equatable { | ||
// MARK: Properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I think the property Data
is missing unless it's meant to be added in a later stage. (server code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Do you have an example of what this data looks like? It wasn't clear from the Swagger document I have and it's not populated for my account. It looks like it's Dictionary<string, object>
on the server, but what is object
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be anything, currently we have int
, bool
and string
values stored in there, like minimum timeout time in minutes. Here you have some keys of that and the methods to get the specified value type from the data object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I may hold off on implementing this for now until we get into policy stuff. There isn't a standard way of decoding JSON like this in Swift, so it'd be helpful to have more context prior to implementing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, no problem. Could a TODO
be added in the code just to note that it's missing and will be addressed later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, added!
let ciphers: [CipherDetailsResponseModel]? | ||
|
||
/// The user's list of collections. | ||
let collections: [CollectionDetailsResponseModel]? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fedemkr These arrays in SyncResponseModel
and other models are marked as nullable: true
in the Swagger document. But from looking at the response I get back from the API, an empty array is returned. Do I need to make these optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can see they don't need to be optional. ciphers
is not being considered null
and collections
is defaulted to empty list so it's safe to remove the ?
(server code)
Thanks for the feedback, @fedemkr!
Nope, I can remove these if they aren't needed.
I thought those were marked as nullable in the Swagger document that I have, but it looks like they aren't. If we know things can't be optional/nullable from the API, it's definitely easier on our side to make them be non-optional. I've updated all the properties that you commented on above. |
struct PolicyResponseModel: Codable, Equatable { | ||
// MARK: Properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, no problem. Could a TODO
be added in the code just to note that it's missing and will be addressed later?
🎟️ Tracking
BIT-162
🚧 Type of change
📔 Objective
Adds the sync API request and response for syncing the user's vault.
📋 Code changes
getSync()
method for making a sync request.⏰ Reminders before review
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes