test models updated
This commit is contained in:
parent
9d3b3bd223
commit
83b8f40e93
|
|
@ -538,9 +538,12 @@
|
|||
B84D64B120A70B7000DD76DA /* NetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */; };
|
||||
B84D64B220A70B7000DD76DA /* NetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */; };
|
||||
B84D64B320A70B7000DD76DA /* NetworkServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */; };
|
||||
B84D64B620A71A8400DD76DA /* ObservableMappablePost.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B520A71A8400DD76DA /* ObservableMappablePost.swift */; };
|
||||
B84D64B720A71A8400DD76DA /* ObservableMappablePost.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B520A71A8400DD76DA /* ObservableMappablePost.swift */; };
|
||||
B84D64B820A71A8400DD76DA /* ObservableMappablePost.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84D64B520A71A8400DD76DA /* ObservableMappablePost.swift */; };
|
||||
B85B766820AC4EC600F837C4 /* Album.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85B766620AC4EA300F837C4 /* Album.swift */; };
|
||||
B85B766920AC4EC700F837C4 /* Album.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85B766620AC4EA300F837C4 /* Album.swift */; };
|
||||
B85B766A20AC4EC700F837C4 /* Album.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85B766620AC4EA300F837C4 /* Album.swift */; };
|
||||
B85B766D20AC51C600F837C4 /* AlbumsContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85B766B20AC51BE00F837C4 /* AlbumsContainer.swift */; };
|
||||
B85B766E20AC51C600F837C4 /* AlbumsContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85B766B20AC51BE00F837C4 /* AlbumsContainer.swift */; };
|
||||
B85B766F20AC51C700F837C4 /* AlbumsContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85B766B20AC51BE00F837C4 /* AlbumsContainer.swift */; };
|
||||
BA6C6DB45950382041948FC5 /* Pods_LeadKit_LeadKit_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFE9323150A9760008093F73 /* Pods_LeadKit_LeadKit_iOS.framework */; };
|
||||
D6EE55093E404DEA62B03DDF /* Pods_LeadKit_LeadKit_watchOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8590CA7831555C295C5DC572 /* Pods_LeadKit_LeadKit_watchOS.framework */; };
|
||||
DEE25FE98D40ED1C168F384A /* Pods_LeadKit_LeadKit_iOS_Extensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */; };
|
||||
|
|
@ -790,7 +793,8 @@
|
|||
A6F32C0E1F6EBE8E00AC08EE /* StringExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = "<group>"; };
|
||||
A854A36EB179651E6D0CC9FB /* Pods_LeadKit_tvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_tvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B84D64B020A70B7000DD76DA /* NetworkServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkServiceTests.swift; sourceTree = "<group>"; };
|
||||
B84D64B520A71A8400DD76DA /* ObservableMappablePost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableMappablePost.swift; sourceTree = "<group>"; };
|
||||
B85B766620AC4EA300F837C4 /* Album.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Album.swift; sourceTree = "<group>"; };
|
||||
B85B766B20AC51BE00F837C4 /* AlbumsContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumsContainer.swift; sourceTree = "<group>"; };
|
||||
BECC6E4BF63781403877B059 /* Pods-LeadKit-LeadKit watchOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit-LeadKit watchOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit-LeadKit watchOS/Pods-LeadKit-LeadKit watchOS.release.xcconfig"; sourceTree = "<group>"; };
|
||||
CB02EAC4E52AF48AD64EC045 /* Pods-LeadKit iOS ExtensionsTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit iOS ExtensionsTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit iOS ExtensionsTests/Pods-LeadKit iOS ExtensionsTests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
CD7003F75FD6DDC97DC99A7A /* Pods-LeadKit iOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit iOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit iOSTests/Pods-LeadKit iOSTests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
|
|
@ -1238,8 +1242,9 @@
|
|||
671463B21EB34B1E00EAB194 /* Models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B85B766620AC4EA300F837C4 /* Album.swift */,
|
||||
B85B766B20AC51BE00F837C4 /* AlbumsContainer.swift */,
|
||||
671463B31EB34B1E00EAB194 /* Post.swift */,
|
||||
B84D64B520A71A8400DD76DA /* ObservableMappablePost.swift */,
|
||||
);
|
||||
path = Models;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -2749,12 +2754,13 @@
|
|||
files = (
|
||||
A6C9A5051F8BC78F009311CC /* SeparatorConfiguration.swift in Sources */,
|
||||
671463CA1EB34B1E00EAB194 /* TestView.swift in Sources */,
|
||||
B84D64B620A71A8400DD76DA /* ObservableMappablePost.swift in Sources */,
|
||||
671463B81EB34B1E00EAB194 /* StubCursor.swift in Sources */,
|
||||
B85B766D20AC51C600F837C4 /* AlbumsContainer.swift in Sources */,
|
||||
671463BB1EB34B1E00EAB194 /* CursorTests.swift in Sources */,
|
||||
A6F32C101F6EBE9600AC08EE /* StringExtensionTests.swift in Sources */,
|
||||
671463BE1EB34B1E00EAB194 /* LoadFromNibTests.swift in Sources */,
|
||||
A6C9A50F1F8BC79D009311CC /* Comparable+Extensions.swift in Sources */,
|
||||
B85B766820AC4EC600F837C4 /* Album.swift in Sources */,
|
||||
671463C41EB34B1E00EAB194 /* Post.swift in Sources */,
|
||||
B84D64B120A70B7000DD76DA /* NetworkServiceTests.swift in Sources */,
|
||||
);
|
||||
|
|
@ -3013,11 +3019,12 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B85B766F20AC51C700F837C4 /* AlbumsContainer.swift in Sources */,
|
||||
671463CC1EB34B1E00EAB194 /* TestView.swift in Sources */,
|
||||
B84D64B320A70B7000DD76DA /* NetworkServiceTests.swift in Sources */,
|
||||
671463BA1EB34B1E00EAB194 /* StubCursor.swift in Sources */,
|
||||
671463BD1EB34B1E00EAB194 /* CursorTests.swift in Sources */,
|
||||
B84D64B820A71A8400DD76DA /* ObservableMappablePost.swift in Sources */,
|
||||
B85B766A20AC4EC700F837C4 /* Album.swift in Sources */,
|
||||
A6F32C121F6EBE9800AC08EE /* StringExtensionTests.swift in Sources */,
|
||||
671463C01EB34B1E00EAB194 /* LoadFromNibTests.swift in Sources */,
|
||||
671463C61EB34B1E00EAB194 /* Post.swift in Sources */,
|
||||
|
|
@ -3175,10 +3182,11 @@
|
|||
B84D64B220A70B7000DD76DA /* NetworkServiceTests.swift in Sources */,
|
||||
671463C51EB34B1E00EAB194 /* Post.swift in Sources */,
|
||||
671463CB1EB34B1E00EAB194 /* TestView.swift in Sources */,
|
||||
B84D64B720A71A8400DD76DA /* ObservableMappablePost.swift in Sources */,
|
||||
B85B766E20AC51C600F837C4 /* AlbumsContainer.swift in Sources */,
|
||||
A6F32C111F6EBE9700AC08EE /* StringExtensionTests.swift in Sources */,
|
||||
671463BC1EB34B1E00EAB194 /* CursorTests.swift in Sources */,
|
||||
671463B91EB34B1E00EAB194 /* StubCursor.swift in Sources */,
|
||||
B85B766920AC4EC700F837C4 /* Album.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,52 +20,37 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import ObjectMapper
|
||||
import LeadKit
|
||||
import RxSwift
|
||||
|
||||
struct ObservableMappablePost: Decodable {
|
||||
|
||||
struct Album: Decodable {
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case userId
|
||||
case postId = "id"
|
||||
case albumId = "id"
|
||||
case title
|
||||
case body
|
||||
}
|
||||
|
||||
|
||||
let userId: Int
|
||||
let postId: Int
|
||||
let albumId: Int
|
||||
let title: String
|
||||
let body: String
|
||||
|
||||
}
|
||||
|
||||
extension ObservableMappablePost: ObservableMappable {
|
||||
|
||||
static func createFrom(map: Map) -> Observable<ObservableMappablePost> {
|
||||
|
||||
extension Album: Equatable {
|
||||
|
||||
static func == (lhs: Album, rhs: Album) -> Bool {
|
||||
return lhs.userId == rhs.userId &&
|
||||
lhs.albumId == rhs.albumId &&
|
||||
lhs.title == rhs.title
|
||||
}
|
||||
}
|
||||
|
||||
extension Album: ObservableMappable {
|
||||
|
||||
static func createFrom(decoder: JSONDecoder, jsonObject: Any) -> Observable<Album> {
|
||||
return Observable.deferredJust {
|
||||
let userId: Int = try map.value("userId")
|
||||
let postId: Int = try map.value("id")
|
||||
let title: String = try map.value("title")
|
||||
let body: String = try map.value("body")
|
||||
|
||||
return ObservableMappablePost(userId: userId,
|
||||
postId: postId,
|
||||
title: title,
|
||||
body: body)
|
||||
let data = try JSONSerialization.data(withJSONObject: jsonObject, options: [])
|
||||
return try decoder.decode(Album.self, from: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ObservableMappablePost: Equatable {
|
||||
|
||||
static func == (lhs: ObservableMappablePost, rhs: ObservableMappablePost) -> Bool {
|
||||
return lhs.userId == rhs.userId &&
|
||||
lhs.postId == rhs.postId &&
|
||||
lhs.title == rhs.title &&
|
||||
lhs.body == rhs.body
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// Copyright (c) 2018 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import LeadKit
|
||||
import RxSwift
|
||||
|
||||
struct AlbumContainer: Decodable {
|
||||
|
||||
let albums: [Album]
|
||||
}
|
||||
|
||||
extension AlbumContainer: ObservableMappable {
|
||||
|
||||
static func createFrom(decoder: JSONDecoder, jsonObject: Any) -> Observable<AlbumContainer> {
|
||||
return Observable.deferredJust { try cast(jsonObject) as [Any] }
|
||||
.flatMap {
|
||||
$0.concurrentRxMap { json -> Album in
|
||||
let data = try JSONSerialization.data(withJSONObject: json, options: [])
|
||||
return try decoder.decode(Album.self, from: data)
|
||||
}
|
||||
}
|
||||
.map {
|
||||
AlbumContainer(albums: $0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
//
|
||||
|
||||
import ObjectMapper
|
||||
import LeadKit
|
||||
import RxSwift
|
||||
|
||||
struct Post: Decodable {
|
||||
|
||||
|
|
@ -55,6 +57,16 @@ extension Post: ImmutableMappable {
|
|||
}
|
||||
}
|
||||
|
||||
extension Post: ObservableMappable {
|
||||
|
||||
static func createFrom(decoder: JSONDecoder, jsonObject: Any) -> Observable<Post> {
|
||||
return Observable.deferredJust {
|
||||
let data = try JSONSerialization.data(withJSONObject: jsonObject, options: [])
|
||||
return try decoder.decode(Post.self, from: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Post: Equatable {
|
||||
|
||||
static func == (lhs: Post, rhs: Post) -> Bool {
|
||||
|
|
|
|||
Loading…
Reference in New Issue