Skip to content

Commit

Permalink
feat: add version_number to FileVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski committed May 31, 2022
1 parent 58b9dde commit 650656a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
15 changes: 12 additions & 3 deletions IntegrationTests/FileModuleIntegrationSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,12 @@ class FileModuleIntegrationSpecs: BaseIntegrationSpecs {
}

// List versions
let iterator = self.client.files.listVersions(fileId: file.id, offset: 0, limit: 1000)
let iterator = self.client.files.listVersions(
fileId: file.id,
offset: 0,
limit: 1000,
fields: ["name,version_number"]
)

waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
iterator.next { result in
Expand All @@ -329,8 +334,10 @@ class FileModuleIntegrationSpecs: BaseIntegrationSpecs {
expect(page.entries.count).to(equal(2))
expect(page.entries[0].id).to(equal(fileVersion2.id))
expect(page.entries[0].name).to(equal(versionName2))
expect(page.entries[0].versionNumber).to(equal("2"))
expect(page.entries[1].id).to(equal(file.fileVersion?.id))
expect(page.entries[1].name).to(equal(versionName1))
expect(page.entries[1].versionNumber).to(equal("1"))
case let .failure(error):
fail("Expected list call to succeed, but instead got \(error)")
}
Expand All @@ -341,11 +348,12 @@ class FileModuleIntegrationSpecs: BaseIntegrationSpecs {

// Get version
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
self.client.files.getVersion(fileId: file.id, fileVersionId: fileVersion2.id, fields: ["name"]) { result in
self.client.files.getVersion(fileId: file.id, fileVersionId: fileVersion2.id, fields: ["name,version_number"]) { result in
switch result {
case let .success(fileVersionItem):
expect(fileVersionItem.id).to(equal(fileVersion2.id))
expect(fileVersionItem.name).to(equal(versionName2))
expect(fileVersionItem.versionNumber).to(equal("2"))
case let .failure(error):
fail("Expected getVersion call to succeed, but instead got \(error)")
}
Expand Down Expand Up @@ -373,11 +381,12 @@ class FileModuleIntegrationSpecs: BaseIntegrationSpecs {
}

waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
self.client.files.get(fileId: file.id) { result in
self.client.files.get(fileId: file.id, fields: ["name,version_number,file_version"]) { result in
switch result {
case let .success(fileItem):
expect(fileItem.fileVersion?.id).to(equal(fileVersion4?.id))
expect(fileItem.name).to(equal(versionName2))
expect(fileItem.versionNumber).to(equal("4"))
case let .failure(error):
fail("Expected get call to succeed, but instead got \(error)")
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/Responses/FileVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class FileVersion: BoxModel {
public let restoredAt: Date?
/// The user who restored the file version.
public let restoredBy: User?
/// The version number of the file version.
public let versionNumber: String?

/// Initializer.
///
Expand Down Expand Up @@ -75,5 +77,6 @@ public class FileVersion: BoxModel {
purgedAt = try BoxJSONDecoder.optionalDecodeDate(json: json, forKey: "purged_at")
restoredAt = try BoxJSONDecoder.optionalDecodeDate(json: json, forKey: "restored_at")
restoredBy = try BoxJSONDecoder.optionalDecode(json: json, forKey: "restored_by")
versionNumber = try BoxJSONDecoder.optionalDecode(json: json, forKey: "version_number")
}
}
2 changes: 1 addition & 1 deletion Tests/Responses/FileVersionSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class FileVersionSpecs: QuickSpec {
expect(fileVersion.id).to(equal("11111"))
expect(fileVersion.sha1).to(equal("66b034c4281cc624495835a3b5cd80edbaaae688"))
expect(fileVersion.name).to(equal("Screen Shot 2015-08-24 at 11.34.42 AM (1).png"))
// expect(fileVersion.extension).to(equal("png"))
expect(fileVersion.size).to(equal(105_459))
expect(fileVersion.versionNumber).to(equal("2"))
expect(fileVersion.uploaderDisplayName).to(equal("Example User"))
expect(fileVersion.createdAt?.iso8601).to(equal("2018-05-29T18:40:53Z"))
expect(fileVersion.modifiedAt?.iso8601).to(equal("2018-05-29T18:40:53Z"))
Expand Down

0 comments on commit 650656a

Please sign in to comment.