Skip to content

Commit

Permalink
Make 'name' field optional (#90)
Browse files Browse the repository at this point in the history
fix: make 'name' field optional

Make `name` field optional for channel and UUID metadata.
  • Loading branch information
parfeon authored Nov 8, 2021
1 parent f05433e commit 999b657
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 31 deletions.
9 changes: 7 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
name: swift
scm: github.com/pubnub/swift
version: "4.1.1"
version: "4.1.2"
schema: 1
changelog:
- date: 2021-11-08
version: 4.1.2
changes:
- type: bug
text: "Make `name` field optional for channel and UUID metadata."
- date: 2021-11-05
version: 4.1.1
changes:
Expand Down Expand Up @@ -424,7 +429,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: PubNub
location: https://github.com/pubnub/swift/archive/refs/tags/4.1.1.zip
location: https://github.com/pubnub/swift/archive/refs/tags/4.1.2.zip
supported-platforms:
supported-operating-systems:
macOS:
Expand Down
4 changes: 2 additions & 2 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MARKETING_VERSION = 4.1.1;
MARKETING_VERSION = 4.1.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -2547,7 +2547,7 @@
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MARKETING_VERSION = 4.1.1;
MARKETING_VERSION = 4.1.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down
2 changes: 1 addition & 1 deletion PubNubSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PubNubSwift'
s.version = '4.1.1'
s.version = '4.1.2'
s.homepage = 'https://github.com/pubnub/swift'
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
s.authors = { 'PubNub, Inc.' => '[email protected]' }
Expand Down
2 changes: 1 addition & 1 deletion Sources/PubNub/Helpers/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct Constant {
}()

static let pubnubSwiftSDKVersion: String = {
"4.1.1"
"4.1.2"
}()

static let appBundleId: String = {
Expand Down
6 changes: 3 additions & 3 deletions Sources/PubNub/Models/PubNubChannelMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public protocol PubNubChannelMetadata {
/// The unique identifier of the Channel
var metadataId: String { get }
/// The name of the Channel
var name: String { get set }
var name: String? { get set }
/// Text describing the purpose of the channel
var channelDescription: String? { get set }
/// The last updated timestamp for the object
Expand Down Expand Up @@ -75,7 +75,7 @@ extension PubNubChannelMetadata {
/// The default implementation of the `PubNubChannelMetadata` protocol
public struct PubNubChannelMetadataBase: PubNubChannelMetadata, Hashable {
public let metadataId: String
public var name: String
public var name: String?
public var channelDescription: String?

public var updated: Date?
Expand All @@ -89,7 +89,7 @@ public struct PubNubChannelMetadataBase: PubNubChannelMetadata, Hashable {

public init(
metadataId: String = UUID().uuidString,
name: String,
name: String? = nil,
channelDescription: String? = nil,
custom concreteCustom: [String: JSONCodableScalar]? = nil,
updated: Date? = nil,
Expand Down
6 changes: 3 additions & 3 deletions Sources/PubNub/Models/PubNubUUIDMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public protocol PubNubUUIDMetadata {
/// The unique identifier of the UUID
var metadataId: String { get }
/// The name of the UUID
var name: String { get set }
var name: String? { get set }
/// The external identifier for the object
var externalId: String? { get set }
/// The profile URL for the object
Expand Down Expand Up @@ -79,7 +79,7 @@ extension PubNubUUIDMetadata {
/// The default implementation of the `PubNubUUIDMetadata` protocol
public struct PubNubUUIDMetadataBase: PubNubUUIDMetadata, Hashable {
public let metadataId: String
public var name: String
public var name: String?
public var externalId: String?
public var profileURL: String?
public var email: String?
Expand All @@ -94,7 +94,7 @@ public struct PubNubUUIDMetadataBase: PubNubUUIDMetadata, Hashable {

public init(
metadataId: String = UUID().uuidString,
name: String,
name: String? = nil,
externalId: String? = nil,
profileURL: String? = nil,
email: String? = nil,
Expand Down
5 changes: 2 additions & 3 deletions Sources/PubNub/Networking/Routers/ObjectsChannelRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct ObjectsChannelRouter: HTTPRouter {

// Custom request body object for .set endpoint
struct SetChannelMetadataRequestBody: JSONCodable {
var name: String
var name: String?
var description: String?
var custom: [String: JSONCodableScalarType]?
}
Expand Down Expand Up @@ -156,8 +156,7 @@ struct ObjectsChannelRouter: HTTPRouter {
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyChannelMetadataId))
case let .set(metadata, _):
return isInvalidForReason(
(metadata.metadataId.isEmpty && metadata.name.isEmpty,
ErrorDescription.invalidChannelMetadata))
(metadata.metadataId.isEmpty, ErrorDescription.invalidChannelMetadata))
case let .remove(metadataId):
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyChannelMetadataId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,9 @@ struct ObjectMetadataPartial: Codable {
} else if let uuid = try? container.decodeIfPresent(PubNubUUIDMetadataBase.self, forKey: .uuid) {
self.uuid = .init(metadataId: uuid.metadataId, metadataObject: uuid)
channel = nil
} else if let nestedContainer = try? container.nestedContainer(keyedBy: NestedCodingKeys.self, forKey: .channel) {
channel = .init(metadataId: try nestedContainer.decode(String.self, forKey: .id), metadataObject: nil)
uuid = nil
} else {
let nestedContainer = try container.nestedContainer(keyedBy: NestedCodingKeys.self, forKey: .uuid)
uuid = .init(metadataId: try nestedContainer.decode(String.self, forKey: .id), metadataObject: nil)
channel = nil
uuid = nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PubNub/Networking/Routers/ObjectsUUIDRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct ObjectsUUIDRouter: HTTPRouter {

// Custom request body object for .set endpoint
struct SetUUIDMetadataRequestBody: JSONCodable {
var name: String
var name: String?
var externalId: String?
var profileURL: String?
var email: String?
Expand Down Expand Up @@ -167,7 +167,7 @@ struct ObjectsUUIDRouter: HTTPRouter {
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyUUIDMetadataId))
case let .set(metadata, _):
return isInvalidForReason(
(metadata.metadataId.isEmpty && metadata.name.isEmpty, ErrorDescription.invalidUUIDMetadata))
(metadata.metadataId.isEmpty, ErrorDescription.invalidUUIDMetadata))
case let .remove(metadataId):
return isInvalidForReason((metadataId.isEmpty, ErrorDescription.emptyUUIDMetadataId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ extension PubNubUUIDMetadataChangeset: Codable {

var changes = [PubNubMetadataChange<PubNubUUIDMetadata>]()
if let name = try container.decodeIfPresent(String.self, forKey: .name) {
changes.append(.string(\.name, name))
changes.append(.stringOptional(\.name, name))
}
if let externalId = try container.decodeIfPresent(ValueOptionJSON<String>.self, forKey: .externalId) {
changes.append(.stringOptional(\.externalId, externalId.value))
Expand Down Expand Up @@ -267,7 +267,7 @@ extension PubNubChannelMetadataChangeset: Codable {

var changes = [PubNubMetadataChange<PubNubChannelMetadata>]()
if let name = try container.decodeIfPresent(String.self, forKey: .name) {
changes.append(.string(\.name, name))
changes.append(.stringOptional(\.name, name))
}
if let description = try container.decodeIfPresent(ValueOptionJSON<String>.self, forKey: .channelDescription) {
changes.append(.stringOptional(\.channelDescription, description.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ extension ObjectsMembershipsRouterTests {
else {
return XCTFail("Could not create mock url session")
}

let firstChannel = PubNubChannelMetadataBase(
metadataId: "FirstChannel", name: "First Channel",
channelDescription: "Channel Description", updated: channeDate, eTag: "ChanneleTag"
)

let lastChannel = PubNubChannelMetadataBase(metadataId: "LastChannel")
let firstMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUser", channelMetadataId: firstChannel.metadataId,
channel: firstChannel,
updated: firstDate, eTag: "FirstETag"
)
let lastMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUser", channelMetadataId: "LastChannel",
channel: lastChannel,
updated: lastDate, eTag: "LastETag"
)

Expand Down Expand Up @@ -171,18 +174,20 @@ extension ObjectsMembershipsRouterTests {
else {
return XCTFail("Could not create mock url session")
}

let firstChannel = PubNubChannelMetadataBase(
metadataId: "FirstChannel", name: "First Channel",
channelDescription: "Channel Description", updated: channeDate, eTag: "ChanneleTag"
)
let lastChannel = PubNubChannelMetadataBase(metadataId: "LastChannel")
let firstMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUser", channelMetadataId: firstChannel.metadataId,
channel: firstChannel,
updated: firstDate, eTag: "FirstETag"
)
let lastMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUser", channelMetadataId: "LastChannel",
channel: lastChannel,
updated: lastDate, eTag: "LastETag"
)

Expand Down Expand Up @@ -218,13 +223,15 @@ extension ObjectsMembershipsRouterTests {
metadataId: "FirstChannel", name: "First Channel",
channelDescription: "Channel Description", updated: channeDate, eTag: "ChanneleTag"
)
let lastChannel = PubNubChannelMetadataBase(metadataId: "LastChannel")
let firstMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUser", channelMetadataId: firstChannel.metadataId,
channel: firstChannel,
updated: firstDate, eTag: "FirstETag"
)
let lastMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUser", channelMetadataId: "LastChannel",
channel: lastChannel,
updated: lastDate, eTag: "LastETag"
)

Expand Down Expand Up @@ -286,6 +293,7 @@ extension ObjectsMembershipsRouterTests {
let firstUUID = PubNubUUIDMetadataBase(
metadataId: "FirstUser", name: "First User", updated: uuidDate, eTag: "UserETag"
)
let lastUUID = PubNubUUIDMetadataBase(metadataId: "LastUser")

let firstMembership = PubNubMembershipMetadataBase(
uuidMetadataId: firstUUID.metadataId, channelMetadataId: "TestChannel",
Expand All @@ -294,6 +302,7 @@ extension ObjectsMembershipsRouterTests {
)
let lastMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "LastUser", channelMetadataId: "TestChannel",
uuid: lastUUID,
custom: ["starred": true],
updated: lastDate, eTag: "LastETag"
)
Expand All @@ -305,6 +314,10 @@ extension ObjectsMembershipsRouterTests {
) { result in
switch result {
case let .success((memberships, nextPage)):
let membs1: [PubNubMembershipMetadataBase] = memberships.compactMap { try? $0.transcode() }
let membs2 = [firstMembership, lastMembership]
print("MEMBS 1: \(membs1)")
print("MEMBS 2: \(membs2)")
XCTAssertEqual(memberships.compactMap { try? $0.transcode() }, [firstMembership, lastMembership])
XCTAssertEqual(try? nextPage?.transcode(), page)
case let .failure(error):
Expand Down Expand Up @@ -381,10 +394,11 @@ extension ObjectsMembershipsRouterTests {
else {
return XCTFail("Could not create mock url session")
}

let firstUUID = PubNubUUIDMetadataBase(
metadataId: "FirstUser", name: "First User", updated: uuidDate, eTag: "UserETag"
)
let lastUUID = PubNubUUIDMetadataBase(metadataId: "LastUser")

let firstMembership = PubNubMembershipMetadataBase(
uuidMetadataId: firstUUID.metadataId, channelMetadataId: "TestChannel",
Expand All @@ -393,6 +407,7 @@ extension ObjectsMembershipsRouterTests {
)
let lastMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "LastUser", channelMetadataId: "TestChannel",
uuid: lastUUID,
custom: ["starred": true],
updated: lastDate, eTag: "LastETag"
)
Expand Down Expand Up @@ -428,6 +443,7 @@ extension ObjectsMembershipsRouterTests {
let firstUUID = PubNubUUIDMetadataBase(
metadataId: "FirstUser", name: "First User", updated: uuidDate, eTag: "UserETag"
)
let lastUUID = PubNubUUIDMetadataBase(metadataId: "LastUser")

let firstMembership = PubNubMembershipMetadataBase(
uuidMetadataId: firstUUID.metadataId, channelMetadataId: "TestChannel",
Expand All @@ -436,6 +452,7 @@ extension ObjectsMembershipsRouterTests {
)
let lastMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "LastUser", channelMetadataId: "TestChannel",
uuid: lastUUID,
custom: ["starred": true],
updated: lastDate, eTag: "LastETag"
)
Expand Down
12 changes: 8 additions & 4 deletions Tests/PubNubTests/Networking/Routers/SubscribeRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,11 @@ extension SubscribeRouterTests {
}

let subscription = SubscribeSessionFactory.shared.getSession(from: config, with: session)


let channel = PubNubChannelMetadataBase(metadataId: "TestSpaceID")
let uuid = PubNubUUIDMetadataBase(metadataId: "TestUserID")
let testMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUserID", channelMetadataId: "TestSpaceID", custom: ["something": true],
uuidMetadataId: "TestUserID", channelMetadataId: "TestSpaceID", uuid: uuid, channel: channel, custom: ["something": true],
updated: DateFormatter.iso8601.date(from: "2019-10-05T23:35:38.457823306Z"), eTag: "TestETag"
)

Expand Down Expand Up @@ -514,9 +516,11 @@ extension SubscribeRouterTests {
}

let subscription = SubscribeSessionFactory.shared.getSession(from: config, with: session)


let channel = PubNubChannelMetadataBase(metadataId: "TestSpaceID")
let uuid = PubNubUUIDMetadataBase(metadataId: "TestUserID")
let testMembership = PubNubMembershipMetadataBase(
uuidMetadataId: "TestUserID", channelMetadataId: "TestSpaceID",
uuidMetadataId: "TestUserID", channelMetadataId: "TestSpaceID", uuid: uuid, channel: channel,
updated: DateFormatter.iso8601.date(from: "2019-10-05T23:35:38.457823306Z"), eTag: "TestETag"
)

Expand Down

0 comments on commit 999b657

Please sign in to comment.