diff --git a/TaiwanReceiptLottery/Info.plist b/TaiwanReceiptLottery/Info.plist new file mode 100644 index 0000000..9bcb244 --- /dev/null +++ b/TaiwanReceiptLottery/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + + diff --git a/TaiwanReceiptLottery/Receipt.swift b/TaiwanReceiptLottery/Receipt.swift new file mode 100644 index 0000000..c7ff5da --- /dev/null +++ b/TaiwanReceiptLottery/Receipt.swift @@ -0,0 +1,28 @@ +// +// Receipt.swift +// TaiwanReceiptLottery +// +// Created by Paul Lee on 2021/9/14. +// + +import Foundation +public struct Receipt { + public enum SpecialFieldBox { + case taxID(String) + case mobileBarCode(String) + case npoCode(String) + case non + } + + let date: Date + let price: Int + let lotteryNumber: String + let specialField: SpecialFieldBox + + public init(date: Date, price: Int, lotteryNumber: String, specialField: SpecialFieldBox) { + self.date = date + self.price = price + self.lotteryNumber = lotteryNumber + self.specialField = specialField + } +} diff --git a/TaiwanReceiptLottery/ReceiptViewModel.swift b/TaiwanReceiptLottery/ReceiptViewModel.swift new file mode 100644 index 0000000..b4d37a2 --- /dev/null +++ b/TaiwanReceiptLottery/ReceiptViewModel.swift @@ -0,0 +1,50 @@ +// +// ReceiptViewModel.swift +// TaiwanReceiptLottery +// +// Created by Paul Lee on 2021/9/14. +// + +import Foundation +public struct ReceiptViewModel { + let receipt: Receipt + public init(_ receipt: Receipt) { + self.receipt = receipt + } + + public var title: String { + switch receipt.specialField { + case .taxID(let id): + return "A B2B receipt has been issued, the company tax id is \(id)." + + case .mobileBarCode: + return "A B2C receipt has been issued." + + case .npoCode: + return "A B2C receipt has been issued." + + case .non: + return "A B2C receipt has been issued." + } + } + + public var body: String { + return "The lottery number is \(receipt.lotteryNumber)." + } + + public var footer: String { + switch receipt.specialField { + case .taxID: + return "You can choose to print out this receipt or send it to your customer through email." + + case .mobileBarCode(let code): + return "The receipt is saved in cloud database with mobile barcode number: \(code)" + + case .npoCode(let code): + return "The lottery opportunity has been donated to a non profit organization, the organization id is: \(code)" + + case .non: + return "The receipt has been printed." + } + } +} diff --git a/TaiwanReceiptLottery/ReceiptViewModelsFactory.swift b/TaiwanReceiptLottery/ReceiptViewModelsFactory.swift new file mode 100644 index 0000000..6a58fcf --- /dev/null +++ b/TaiwanReceiptLottery/ReceiptViewModelsFactory.swift @@ -0,0 +1,13 @@ +// +// ReceiptViewModelsFactory.swift +// TaiwanReceiptLottery +// +// Created by Paul Lee on 2021/9/14. +// + +import Foundation +public class ViewModelsFactory { + public static func makeViewModels(_ receipts: [Receipt]) -> [ReceiptViewModel] { + receipts.map { ReceiptViewModel($0) } + } +} diff --git a/TaiwanReceiptLottery/TaiwanReceiptLottery.h b/TaiwanReceiptLottery/TaiwanReceiptLottery.h new file mode 100644 index 0000000..0872c86 --- /dev/null +++ b/TaiwanReceiptLottery/TaiwanReceiptLottery.h @@ -0,0 +1,18 @@ +// +// TaiwanReceiptLottery.h +// TaiwanReceiptLottery +// +// Created by Paul Lee on 2021/9/14. +// + +#import + +//! Project version number for TaiwanReceiptLottery. +FOUNDATION_EXPORT double TaiwanReceiptLotteryVersionNumber; + +//! Project version string for TaiwanReceiptLottery. +FOUNDATION_EXPORT const unsigned char TaiwanReceiptLotteryVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/TaiwanReceiptLotteryKata.xcodeproj/project.pbxproj b/TaiwanReceiptLotteryKata.xcodeproj/project.pbxproj index a16ced2..468ee40 100644 --- a/TaiwanReceiptLotteryKata.xcodeproj/project.pbxproj +++ b/TaiwanReceiptLotteryKata.xcodeproj/project.pbxproj @@ -7,6 +7,13 @@ objects = { /* Begin PBXBuildFile section */ + 63B0752126F0675F00F361CC /* TaiwanReceiptLottery.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63B0751826F0675F00F361CC /* TaiwanReceiptLottery.framework */; }; + 63B0752626F0675F00F361CC /* ReceiptViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0752526F0675F00F361CC /* ReceiptViewModelTests.swift */; }; + 63B0752826F0675F00F361CC /* TaiwanReceiptLottery.h in Headers */ = {isa = PBXBuildFile; fileRef = 63B0751A26F0675F00F361CC /* TaiwanReceiptLottery.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 63B0753026F081AA00F361CC /* Receipt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0752F26F081AA00F361CC /* Receipt.swift */; }; + 63B0753226F081BB00F361CC /* ReceiptViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0753126F081BB00F361CC /* ReceiptViewModel.swift */; }; + 63B0753426F0881700F361CC /* ViewModelsFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0753326F0881700F361CC /* ViewModelsFactoryTests.swift */; }; + 63B0753626F0883500F361CC /* ReceiptViewModelsFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B0753526F0883500F361CC /* ReceiptViewModelsFactory.swift */; }; 63DECBD126EF3DD200802D7D /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 63DECBD026EF3DD200802D7D /* README.md */; }; 63E8F32825B293D800468177 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E8F32725B293D800468177 /* AppDelegate.swift */; }; 63E8F32A25B293D800468177 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E8F32925B293D800468177 /* SceneDelegate.swift */; }; @@ -18,14 +25,14 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 63E8F33B25B293DA00468177 /* PBXContainerItemProxy */ = { + 63B0752226F0675F00F361CC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 63E8F31C25B293D800468177 /* Project object */; proxyType = 1; - remoteGlobalIDString = 63E8F32325B293D800468177; - remoteInfo = TaiwanReceiptLotteryKata; + remoteGlobalIDString = 63B0751726F0675F00F361CC; + remoteInfo = TaiwanReceiptLottery; }; - 63E8F34625B293DA00468177 /* PBXContainerItemProxy */ = { + 63E8F33B25B293DA00468177 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 63E8F31C25B293D800468177 /* Project object */; proxyType = 1; @@ -35,6 +42,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 63B0751826F0675F00F361CC /* TaiwanReceiptLottery.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TaiwanReceiptLottery.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 63B0751A26F0675F00F361CC /* TaiwanReceiptLottery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TaiwanReceiptLottery.h; sourceTree = ""; }; + 63B0751B26F0675F00F361CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 63B0752026F0675F00F361CC /* TaiwanReceiptLotteryTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TaiwanReceiptLotteryTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 63B0752526F0675F00F361CC /* ReceiptViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptViewModelTests.swift; sourceTree = ""; }; + 63B0752726F0675F00F361CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 63B0752F26F081AA00F361CC /* Receipt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Receipt.swift; sourceTree = ""; }; + 63B0753126F081BB00F361CC /* ReceiptViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptViewModel.swift; sourceTree = ""; }; + 63B0753326F0881700F361CC /* ViewModelsFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModelsFactoryTests.swift; sourceTree = ""; }; + 63B0753526F0883500F361CC /* ReceiptViewModelsFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptViewModelsFactory.swift; sourceTree = ""; }; 63DECBD026EF3DD200802D7D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 63E8F32425B293D800468177 /* TaiwanReceiptLotteryKata.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TaiwanReceiptLotteryKata.app; sourceTree = BUILT_PRODUCTS_DIR; }; 63E8F32725B293D800468177 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -47,25 +64,32 @@ 63E8F33A25B293DA00468177 /* TaiwanReceiptLotteryKataTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TaiwanReceiptLotteryKataTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 63E8F33E25B293DA00468177 /* TaiwanReceiptLotteryKataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaiwanReceiptLotteryKataTests.swift; sourceTree = ""; }; 63E8F34025B293DA00468177 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 63E8F34525B293DA00468177 /* TaiwanReceiptLotteryKataUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TaiwanReceiptLotteryKataUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 63E8F32125B293D800468177 /* Frameworks */ = { + 63B0751526F0675F00F361CC /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 63E8F33725B293DA00468177 /* Frameworks */ = { + 63B0751D26F0675F00F361CC /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 63B0752126F0675F00F361CC /* TaiwanReceiptLottery.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; - 63E8F34225B293DA00468177 /* Frameworks */ = { + 63E8F32125B293D800468177 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 63E8F33725B293DA00468177 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( @@ -75,12 +99,36 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 63B0751926F0675F00F361CC /* TaiwanReceiptLottery */ = { + isa = PBXGroup; + children = ( + 63B0751A26F0675F00F361CC /* TaiwanReceiptLottery.h */, + 63B0752F26F081AA00F361CC /* Receipt.swift */, + 63B0753126F081BB00F361CC /* ReceiptViewModel.swift */, + 63B0753526F0883500F361CC /* ReceiptViewModelsFactory.swift */, + 63B0751B26F0675F00F361CC /* Info.plist */, + ); + path = TaiwanReceiptLottery; + sourceTree = ""; + }; + 63B0752426F0675F00F361CC /* TaiwanReceiptLotteryTests */ = { + isa = PBXGroup; + children = ( + 63B0752526F0675F00F361CC /* ReceiptViewModelTests.swift */, + 63B0753326F0881700F361CC /* ViewModelsFactoryTests.swift */, + 63B0752726F0675F00F361CC /* Info.plist */, + ); + path = TaiwanReceiptLotteryTests; + sourceTree = ""; + }; 63E8F31B25B293D800468177 = { isa = PBXGroup; children = ( 63DECBD026EF3DD200802D7D /* README.md */, 63E8F32625B293D800468177 /* TaiwanReceiptLotteryKata */, 63E8F33D25B293DA00468177 /* TaiwanReceiptLotteryKataTests */, + 63B0751926F0675F00F361CC /* TaiwanReceiptLottery */, + 63B0752426F0675F00F361CC /* TaiwanReceiptLotteryTests */, 63E8F32525B293D800468177 /* Products */, ); sourceTree = ""; @@ -90,7 +138,8 @@ children = ( 63E8F32425B293D800468177 /* TaiwanReceiptLotteryKata.app */, 63E8F33A25B293DA00468177 /* TaiwanReceiptLotteryKataTests.xctest */, - 63E8F34525B293DA00468177 /* TaiwanReceiptLotteryKataUITests.xctest */, + 63B0751826F0675F00F361CC /* TaiwanReceiptLottery.framework */, + 63B0752026F0675F00F361CC /* TaiwanReceiptLotteryTests.xctest */, ); name = Products; sourceTree = ""; @@ -120,7 +169,54 @@ }; /* End PBXGroup section */ +/* Begin PBXHeadersBuildPhase section */ + 63B0751326F0675F00F361CC /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 63B0752826F0675F00F361CC /* TaiwanReceiptLottery.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + /* Begin PBXNativeTarget section */ + 63B0751726F0675F00F361CC /* TaiwanReceiptLottery */ = { + isa = PBXNativeTarget; + buildConfigurationList = 63B0752D26F0675F00F361CC /* Build configuration list for PBXNativeTarget "TaiwanReceiptLottery" */; + buildPhases = ( + 63B0751326F0675F00F361CC /* Headers */, + 63B0751426F0675F00F361CC /* Sources */, + 63B0751526F0675F00F361CC /* Frameworks */, + 63B0751626F0675F00F361CC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = TaiwanReceiptLottery; + productName = TaiwanReceiptLottery; + productReference = 63B0751826F0675F00F361CC /* TaiwanReceiptLottery.framework */; + productType = "com.apple.product-type.framework"; + }; + 63B0751F26F0675F00F361CC /* TaiwanReceiptLotteryTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 63B0752E26F0675F00F361CC /* Build configuration list for PBXNativeTarget "TaiwanReceiptLotteryTests" */; + buildPhases = ( + 63B0751C26F0675F00F361CC /* Sources */, + 63B0751D26F0675F00F361CC /* Frameworks */, + 63B0751E26F0675F00F361CC /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 63B0752326F0675F00F361CC /* PBXTargetDependency */, + ); + name = TaiwanReceiptLotteryTests; + productName = TaiwanReceiptLotteryTests; + productReference = 63B0752026F0675F00F361CC /* TaiwanReceiptLotteryTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; 63E8F32325B293D800468177 /* TaiwanReceiptLotteryKata */ = { isa = PBXNativeTarget; buildConfigurationList = 63E8F34E25B293DA00468177 /* Build configuration list for PBXNativeTarget "TaiwanReceiptLotteryKata" */; @@ -156,33 +252,22 @@ productReference = 63E8F33A25B293DA00468177 /* TaiwanReceiptLotteryKataTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 63E8F34425B293DA00468177 /* TaiwanReceiptLotteryKataUITests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 63E8F35425B293DA00468177 /* Build configuration list for PBXNativeTarget "TaiwanReceiptLotteryKataUITests" */; - buildPhases = ( - 63E8F34125B293DA00468177 /* Sources */, - 63E8F34225B293DA00468177 /* Frameworks */, - 63E8F34325B293DA00468177 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 63E8F34725B293DA00468177 /* PBXTargetDependency */, - ); - name = TaiwanReceiptLotteryKataUITests; - productName = TaiwanReceiptLotteryKataUITests; - productReference = 63E8F34525B293DA00468177 /* TaiwanReceiptLotteryKataUITests.xctest */; - productType = "com.apple.product-type.bundle.ui-testing"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 63E8F31C25B293D800468177 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 1220; + LastSwiftUpdateCheck = 1250; LastUpgradeCheck = 1220; TargetAttributes = { + 63B0751726F0675F00F361CC = { + CreatedOnToolsVersion = 12.5; + LastSwiftMigration = 1250; + }; + 63B0751F26F0675F00F361CC = { + CreatedOnToolsVersion = 12.5; + }; 63E8F32325B293D800468177 = { CreatedOnToolsVersion = 12.2; }; @@ -190,10 +275,6 @@ CreatedOnToolsVersion = 12.2; TestTargetID = 63E8F32325B293D800468177; }; - 63E8F34425B293DA00468177 = { - CreatedOnToolsVersion = 12.2; - TestTargetID = 63E8F32325B293D800468177; - }; }; }; buildConfigurationList = 63E8F31F25B293D800468177 /* Build configuration list for PBXProject "TaiwanReceiptLotteryKata" */; @@ -211,12 +292,27 @@ targets = ( 63E8F32325B293D800468177 /* TaiwanReceiptLotteryKata */, 63E8F33925B293DA00468177 /* TaiwanReceiptLotteryKataTests */, - 63E8F34425B293DA00468177 /* TaiwanReceiptLotteryKataUITests */, + 63B0751726F0675F00F361CC /* TaiwanReceiptLottery */, + 63B0751F26F0675F00F361CC /* TaiwanReceiptLotteryTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 63B0751626F0675F00F361CC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 63B0751E26F0675F00F361CC /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 63E8F32225B293D800468177 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -235,53 +331,58 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 63E8F34325B293DA00468177 /* Resources */ = { - isa = PBXResourcesBuildPhase; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 63B0751426F0675F00F361CC /* Sources */ = { + isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 63B0753626F0883500F361CC /* ReceiptViewModelsFactory.swift in Sources */, + 63B0753026F081AA00F361CC /* Receipt.swift in Sources */, + 63B0753226F081BB00F361CC /* ReceiptViewModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 63E8F32025B293D800468177 /* Sources */ = { + 63B0751C26F0675F00F361CC /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 63E8F32C25B293D800468177 /* ReceiptViewController.swift in Sources */, - 63E8F32825B293D800468177 /* AppDelegate.swift in Sources */, - 63E8F32A25B293D800468177 /* SceneDelegate.swift in Sources */, + 63B0752626F0675F00F361CC /* ReceiptViewModelTests.swift in Sources */, + 63B0753426F0881700F361CC /* ViewModelsFactoryTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - 63E8F33625B293DA00468177 /* Sources */ = { + 63E8F32025B293D800468177 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 63E8F33F25B293DA00468177 /* TaiwanReceiptLotteryKataTests.swift in Sources */, + 63E8F32C25B293D800468177 /* ReceiptViewController.swift in Sources */, + 63E8F32825B293D800468177 /* AppDelegate.swift in Sources */, + 63E8F32A25B293D800468177 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - 63E8F34125B293DA00468177 /* Sources */ = { + 63E8F33625B293DA00468177 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 63E8F33F25B293DA00468177 /* TaiwanReceiptLotteryKataTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 63E8F33C25B293DA00468177 /* PBXTargetDependency */ = { + 63B0752326F0675F00F361CC /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 63E8F32325B293D800468177 /* TaiwanReceiptLotteryKata */; - targetProxy = 63E8F33B25B293DA00468177 /* PBXContainerItemProxy */; + target = 63B0751726F0675F00F361CC /* TaiwanReceiptLottery */; + targetProxy = 63B0752226F0675F00F361CC /* PBXContainerItemProxy */; }; - 63E8F34725B293DA00468177 /* PBXTargetDependency */ = { + 63E8F33C25B293DA00468177 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 63E8F32325B293D800468177 /* TaiwanReceiptLotteryKata */; - targetProxy = 63E8F34625B293DA00468177 /* PBXContainerItemProxy */; + targetProxy = 63E8F33B25B293DA00468177 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -305,6 +406,113 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 63B0752926F0675F00F361CC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = 7S9CF6BJNF; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = TaiwanReceiptLottery/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.3; + PRODUCT_BUNDLE_IDENTIFIER = com.paul.lee.TaiwanReceiptLottery; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 63B0752A26F0675F00F361CC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = 7S9CF6BJNF; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = TaiwanReceiptLottery/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.3; + PRODUCT_BUNDLE_IDENTIFIER = com.paul.lee.TaiwanReceiptLottery; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 63B0752B26F0675F00F361CC /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 7S9CF6BJNF; + INFOPLIST_FILE = TaiwanReceiptLotteryTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.3; + PRODUCT_BUNDLE_IDENTIFIER = com.paul.lee.TaiwanReceiptLotteryTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 63B0752C26F0675F00F361CC /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 7S9CF6BJNF; + INFOPLIST_FILE = TaiwanReceiptLotteryTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.3; + PRODUCT_BUNDLE_IDENTIFIER = com.paul.lee.TaiwanReceiptLotteryTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; 63E8F34C25B293DA00468177 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -503,49 +711,27 @@ }; name = Release; }; - 63E8F35525B293DA00468177 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 7S9CF6BJNF; - INFOPLIST_FILE = TaiwanReceiptLotteryKataUITests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.hylee.TaiwanReceiptLotteryKataUITests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - TEST_TARGET_NAME = TaiwanReceiptLotteryKata; - }; - name = Debug; - }; - 63E8F35625B293DA00468177 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 7S9CF6BJNF; - INFOPLIST_FILE = TaiwanReceiptLotteryKataUITests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.hylee.TaiwanReceiptLotteryKataUITests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - TEST_TARGET_NAME = TaiwanReceiptLotteryKata; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 63B0752D26F0675F00F361CC /* Build configuration list for PBXNativeTarget "TaiwanReceiptLottery" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 63B0752926F0675F00F361CC /* Debug */, + 63B0752A26F0675F00F361CC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 63B0752E26F0675F00F361CC /* Build configuration list for PBXNativeTarget "TaiwanReceiptLotteryTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 63B0752B26F0675F00F361CC /* Debug */, + 63B0752C26F0675F00F361CC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 63E8F31F25B293D800468177 /* Build configuration list for PBXProject "TaiwanReceiptLotteryKata" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -573,15 +759,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 63E8F35425B293DA00468177 /* Build configuration list for PBXNativeTarget "TaiwanReceiptLotteryKataUITests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 63E8F35525B293DA00468177 /* Debug */, - 63E8F35625B293DA00468177 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = 63E8F31C25B293D800468177 /* Project object */; diff --git a/TaiwanReceiptLotteryKata.xcodeproj/xcshareddata/xcschemes/TaiwanReceiptLottery.xcscheme b/TaiwanReceiptLotteryKata.xcodeproj/xcshareddata/xcschemes/TaiwanReceiptLottery.xcscheme new file mode 100644 index 0000000..9ab80f1 --- /dev/null +++ b/TaiwanReceiptLotteryKata.xcodeproj/xcshareddata/xcschemes/TaiwanReceiptLottery.xcscheme @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TaiwanReceiptLotteryTests/Info.plist b/TaiwanReceiptLotteryTests/Info.plist new file mode 100644 index 0000000..64d65ca --- /dev/null +++ b/TaiwanReceiptLotteryTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/TaiwanReceiptLotteryTests/ReceiptViewModelTests.swift b/TaiwanReceiptLotteryTests/ReceiptViewModelTests.swift new file mode 100644 index 0000000..0e95d2a --- /dev/null +++ b/TaiwanReceiptLotteryTests/ReceiptViewModelTests.swift @@ -0,0 +1,44 @@ +// +// ReceiptViewModelTests.swift +// ReceiptViewModelTests +// +// Created by Paul Lee on 2021/9/14. +// + +import XCTest +import TaiwanReceiptLottery + +class ReceiptViewModelTests: XCTestCase { + + func test_presentB2BReceipt() { + let sut = ReceiptViewModel(Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .taxID("45002931"))) + XCTAssertEqual(sut.title, "A B2B receipt has been issued, the company tax id is 45002931.", "title") + XCTAssertEqual(sut.body, "The lottery number is AA-00000001.", "body") + XCTAssertEqual(sut.footer, "You can choose to print out this receipt or send it to your customer through email.", "footer") + } + + func test_presentMobileBarCodeReceipt() { + let sut = ReceiptViewModel(Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .mobileBarCode("/AB201C9"))) + + XCTAssertEqual(sut.title, "A B2C receipt has been issued.", "title") + XCTAssertEqual(sut.body, "The lottery number is AA-00000001.", "body") + XCTAssertEqual(sut.footer, "The receipt is saved in cloud database with mobile barcode number: /AB201C9", "footer") + } + + func test_presentDonatedReceipt() { + let sut = ReceiptViewModel(Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .npoCode("25885"))) + + XCTAssertEqual(sut.title, "A B2C receipt has been issued.", "title") + XCTAssertEqual(sut.body, "The lottery number is AA-00000001.", "body") + XCTAssertEqual(sut.footer, "The lottery opportunity has been donated to a non profit organization, the organization id is: 25885", "footer") + } + + func test_presentPrintedB2CReceipt() { + let sut = ReceiptViewModel(Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .non)) + + XCTAssertEqual(sut.title, "A B2C receipt has been issued.", "title") + XCTAssertEqual(sut.body, "The lottery number is AA-00000001.", "body") + XCTAssertEqual(sut.footer, "The receipt has been printed.", "footer") + } + +} diff --git a/TaiwanReceiptLotteryTests/ViewModelsFactoryTests.swift b/TaiwanReceiptLotteryTests/ViewModelsFactoryTests.swift new file mode 100644 index 0000000..bc0e303 --- /dev/null +++ b/TaiwanReceiptLotteryTests/ViewModelsFactoryTests.swift @@ -0,0 +1,33 @@ +// +// ViewModelsFactoryTests.swift +// TaiwanReceiptLotteryTests +// +// Created by Paul Lee on 2021/9/14. +// + +import XCTest +import TaiwanReceiptLottery + +class ViewModelsFactoryTests: XCTestCase { + + func test_makeViewModelCollection() { + let receipts = [ + Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .taxID("45002931")), + Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .mobileBarCode("/AB201C9")), + Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .npoCode("25885")), + Receipt(date: Date(), price: 100, lotteryNumber: "AA-00000001", specialField: .non) + ] + + let vms = ViewModelsFactory.makeViewModels(receipts) + + let footers = vms.map { $0.footer } + XCTAssertEqual( + footers, + ["You can choose to print out this receipt or send it to your customer through email.", + "The receipt is saved in cloud database with mobile barcode number: /AB201C9", + "The lottery opportunity has been donated to a non profit organization, the organization id is: 25885", + "The receipt has been printed." + ]) + } + +}