Commit 16c0b66c authored by Franco Nicolas Castagna's avatar Franco Nicolas Castagna
Browse files

Corregimos algunas cosas

parent 22050353
...@@ -297,9 +297,8 @@ TestCase subclass: #TusLibrosSystemFacadeTest ...@@ -297,9 +297,8 @@ TestCase subclass: #TusLibrosSystemFacadeTest
poolDictionaries: '' poolDictionaries: ''
category: 'TusLibros'! category: 'TusLibros'!
!TusLibrosSystemFacadeTest methodsFor: 'test - cart adding' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart adding' stamp: 'Castagna 7/23/2020 15:51:18'!
test04CanNotAddItemsToANotCreatedCart test04CanNotAddItemsToANotCreatedCart
self self
should: [ interface add: 3 of: 'book1' toCartWithId: invalidCartId . ] should: [ interface add: 3 of: 'book1' toCartWithId: invalidCartId . ]
...@@ -328,13 +327,12 @@ test05CanAddItemsToACreatedCart ...@@ -328,13 +327,12 @@ test05CanAddItemsToACreatedCart
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart adding' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart adding' stamp: 'Castagna 7/23/2020 15:51:48'!
test06CanNotAddItemsThatNotBelongsToStore test06CanNotAddItemsThatNotBelongsToStore
| cartId cart session | | cartId cart session |
cartId _ interface createCartFor: 'user1' with: 'pass1'. cartId _ interface createCartFor: 'user1' with: 'pass1'.
session _ interface cartSessions at: cartId. session _ interface cartSessions at: cartId.
cart _ session cart. cart _ session cart.
...@@ -367,6 +365,24 @@ test18CanNotAddItemsToCartIfSessionHasExpired ...@@ -367,6 +365,24 @@ test18CanNotAddItemsToCartIfSessionHasExpired
]. ].
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart adding' stamp: 'Castagna 7/23/2020 15:52:08'!
test21addingItemsResetsSessionTime
| cartId session |
cartId _ interface createCartFor: 'user1' with: 'pass1'.
session _ interface cartSessions at: cartId.
clock advance: (interface sessionDuration - 1 minutes).
interface add: 3 of: 'validBook' toCartWithId: cartId.
self assert: session lastUsedTime equals: clock currentTime.
! !
!TusLibrosSystemFacadeTest methodsFor: 'valid users and passwords' stamp: 'Castagna 7/17/2020 23:28:10'! !TusLibrosSystemFacadeTest methodsFor: 'valid users and passwords' stamp: 'Castagna 7/17/2020 23:28:10'!
validUsersAndPasswords validUsersAndPasswords
...@@ -383,7 +399,6 @@ validUsersAndPasswords ...@@ -383,7 +399,6 @@ validUsersAndPasswords
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/21/2020 23:42:14'!
test01CannotCreateCartWithInvalidUser test01CannotCreateCartWithInvalidUser
...@@ -401,30 +416,22 @@ test01CannotCreateCartWithInvalidUser ...@@ -401,30 +416,22 @@ test01CannotCreateCartWithInvalidUser
self assert: anError messageText = TusLibrosSystemFacade invalidUserAndOrPasswordErrorMessage . self assert: anError messageText = TusLibrosSystemFacade invalidUserAndOrPasswordErrorMessage .
]! ! ]! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/23/2020 15:50:59'!
test02CannotCreateCartWithInvalidPassword test02CannotCreateCartWithInvalidPassword
| aUser aPassword |
aUser _ 'user3'.
aPassword _ 'pass4'.
self self
should: [ interface createCartFor: aUser with: aPassword.] should: [ interface createCartFor: 'user3' with: 'pass4'.]
raise: Error - MessageNotUnderstood raise: Error - MessageNotUnderstood
withExceptionDo: [ :anError | withExceptionDo: [ :anError |
self assert: anError messageText = TusLibrosSystemFacade invalidUserAndOrPasswordErrorMessage. self assert: anError messageText = TusLibrosSystemFacade invalidUserAndOrPasswordErrorMessage.
]! ! ]! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/21/2020 23:42:15'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/23/2020 15:50:23'!
test03CanCreateCartWithValidUserAndPassword test03CanCreateCartWithValidUserAndPassword
| aUser aPassword cartId | | cartId |
aUser _ 'user3'.
aPassword _ 'pass3'.
cartId _ interface createCartFor: aUser with: aPassword. cartId _ interface createCartFor: 'user3' with: 'pass3'.
self assert: interface cartSessions keys includes: cartId. self assert: interface cartSessions keys includes: cartId.
! ! ! !
...@@ -452,19 +459,19 @@ setUp ...@@ -452,19 +459,19 @@ setUp
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - list purchases' stamp: 'Castagna 7/21/2020 23:42:15'! !TusLibrosSystemFacadeTest methodsFor: 'test - list purchases' stamp: 'Castagna 7/23/2020 15:54:33'!
test14CanNotListPurchasesWithInvalidPassword test14CanNotListPurchasesWithInvalidPassword
| cartId cart session | | cartId cart session |
cartId _ interface createCartFor: 'user1' with: 'pass1'. cartId _ interface createCartFor: 'user3' with: 'pass3'.
session _ interface cartSessions at: cartId. session _ interface cartSessions at: cartId.
cart _ session cart. cart _ session cart.
cart add: 2 of: 'validBook'. cart add: 2 of: 'validBook'.
self self
should: [ interface listPurchasesOfUser: 'user4' withPassword: 'pass4'] should: [ interface listPurchasesOfUser: 'user3' withPassword: 'pass4']
raise: Error - MessageNotUnderstood raise: Error - MessageNotUnderstood
withExceptionDo: [ withExceptionDo: [
:anError | :anError |
...@@ -478,19 +485,11 @@ test14CanNotListPurchasesWithInvalidPassword ...@@ -478,19 +485,11 @@ test14CanNotListPurchasesWithInvalidPassword
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - list purchases' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - list purchases' stamp: 'Castagna 7/23/2020 15:56:06'!
test15CanNotListPurchasesWithInvalidUser test15CanNotListPurchasesWithInvalidUser
| cartId cart session |
cartId _ interface createCartFor: 'user1' with: 'pass1'.
session _ interface cartSessions at: cartId.
cart _ session cart.
cart add: 2 of: 'validBook'.
self self
should: [ interface listPurchasesOfUser: 'user1' withPassword: 'pass4'] should: [ interface listPurchasesOfUser: 'user4' withPassword: 'pass2']
raise: Error - MessageNotUnderstood raise: Error - MessageNotUnderstood
withExceptionDo: [ withExceptionDo: [
:anError | :anError |
...@@ -583,7 +582,7 @@ test11CanNotCheckoutAnEmptyCart ...@@ -583,7 +582,7 @@ test11CanNotCheckoutAnEmptyCart
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/23/2020 15:58:18'!
test12CanCheckoutACartCorrectly test12CanCheckoutACartCorrectly
| cartId cart total session debitedAmount debitedCreditCard | | cartId cart total session debitedAmount debitedCreditCard |
...@@ -607,12 +606,11 @@ test12CanCheckoutACartCorrectly ...@@ -607,12 +606,11 @@ test12CanCheckoutACartCorrectly
self assert: debitedCreditCard number equals: validCardNumber. self assert: debitedCreditCard number equals: validCardNumber.
self assert: debitedCreditCard expiration equals: expirationDate. self assert: debitedCreditCard expiration equals: expirationDate.
self assert: debitedAmount = total. self assert: debitedAmount = total.
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/23/2020 16:03:18'!
test13CanNotCheckoutWithAnInvalidCreditCart test13CanNotCheckoutWithAnInvalidCreditCard
| cartId cart session | | cartId cart session |
...@@ -628,7 +626,7 @@ test13CanNotCheckoutWithAnInvalidCreditCart ...@@ -628,7 +626,7 @@ test13CanNotCheckoutWithAnInvalidCreditCart
withExceptionDo: [ withExceptionDo: [
:anError | self assert: anError messageText equals: CreditCard invalidCreditCardNumberErrorMessage. :anError | self assert: anError messageText equals: CreditCard invalidCreditCardNumberErrorMessage.
self assert: interface cartSessions keys includes: cartId. self assert: interface cartSessions keys includes: cartId.
self assert: cart includes: 'validBook'. self assert: (cart items occurrencesOf: 'validBook') equals: 3.
self assert: cart items size equals: 3. self assert: cart items size equals: 3.
]. ].
...@@ -636,13 +634,13 @@ test13CanNotCheckoutWithAnInvalidCreditCart ...@@ -636,13 +634,13 @@ test13CanNotCheckoutWithAnInvalidCreditCart
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/23/2020 16:03:39'!
test20CanNotCheckoutCartIfSessionHasExpired test20CanNotCheckoutCartIfSessionHasExpired
| cartId | | cartId |
cartId _ interface createCartFor: 'user1' with: 'pass1'. cartId _ interface createCartFor: 'user1' with: 'pass1'.
interface add: 2 of: 'validBook' toCartWithId: cartId. interface add: 2 of: 'validBook' toCartWithId: cartId.
clock advance: (interface sessionDuration + 1 minutes). clock advance: (interface sessionDuration + 1 minutes).
...@@ -655,8 +653,8 @@ test20CanNotCheckoutCartIfSessionHasExpired ...@@ -655,8 +653,8 @@ test20CanNotCheckoutCartIfSessionHasExpired
]. ].
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/23/2020 15:44:38'!
test21CartShouldBeEmptyAfterCheckout test23CheckoutClosesCartSession
| cartId cart session debitedAmount debitedCreditCard | | cartId cart session debitedAmount debitedCreditCard |
...@@ -673,26 +671,31 @@ test21CartShouldBeEmptyAfterCheckout ...@@ -673,26 +671,31 @@ test21CartShouldBeEmptyAfterCheckout
interface checkout: cartId ownedBy: 'Alan Kay' withCreditCardNumber: validCardNumber withExpirationDate: expirationDate. interface checkout: cartId ownedBy: 'Alan Kay' withCreditCardNumber: validCardNumber withExpirationDate: expirationDate.
self assert: cart items isEmpty. self
should: [ interface checkout: cartId ownedBy: 'Alan Kay' withCreditCardNumber: validCardNumber withExpirationDate: expirationDate. ]
raise: Error - MessageNotUnderstood
withExceptionDo: [
:anError |
self assert: anError messageText equals: interface class invalidCartIdErrorMessage.
self deny: ((interface cartSessions keys) includes: cartId).
].
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/23/2020 16:04:32'!
test07CanNotListAnInvalidCart test07CanNotListAnInvalidCart
self self
should: [ interface listCartWithId: invalidCartId. ] should: [ interface listCartWithId: invalidCartId. ]
raise: Error - MessageNotUnderstood raise: Error - MessageNotUnderstood
withExceptionDo: [ withExceptionDo: [ :anError | self assert: anError messageText equals: interface class invalidCartIdErrorMessage. ].
:anError |
self assert: anError messageText equals: interface class invalidCartIdErrorMessage.
].
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/23/2020 16:04:54'!
test08ListingAnEmptyCartShowsAnEmptyDictionary test08ListingAnEmptyCartShowsAnEmptyBag
| cartId | | cartId |
...@@ -722,7 +725,7 @@ test09ListingACartShowsCartItemsCorrectly ...@@ -722,7 +725,7 @@ test09ListingACartShowsCartItemsCorrectly
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/21/2020 23:42:14'! !TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/23/2020 16:05:16'!
test19CanNotListCartItemsIfSessionHasExpired test19CanNotListCartItemsIfSessionHasExpired
| cartId | | cartId |
...@@ -736,11 +739,27 @@ test19CanNotListCartItemsIfSessionHasExpired ...@@ -736,11 +739,27 @@ test19CanNotListCartItemsIfSessionHasExpired
should: [ interface listCartWithId: cartId ] should: [ interface listCartWithId: cartId ]
raise: Error - MessageNotUnderstood raise: Error - MessageNotUnderstood
withExceptionDo: [ withExceptionDo: [
:anError | :anError | self assert: anError messageText equals: interface class sessionHasExpiredErrorMessage .
self assert: anError messageText equals: interface class sessionHasExpiredErrorMessage .
]. ].
! ! ! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/23/2020 15:47:10'!
test22listCartResetsSessionTime
| cartId session |
cartId _ interface createCartFor: 'user1' with: 'pass1'.
session _ interface cartSessions at: cartId.
clock advance: (interface sessionDuration - 1 minutes).
interface listCartWithId: cartId.
self assert: session lastUsedTime equals: clock currentTime.
! !
!TusLibrosSystemFacadeTest methodsFor: 'merchant processor protocol' stamp: 'Castagna 7/21/2020 20:17:27'! !TusLibrosSystemFacadeTest methodsFor: 'merchant processor protocol' stamp: 'Castagna 7/21/2020 20:17:27'!
...@@ -867,24 +886,12 @@ Object subclass: #CartSession ...@@ -867,24 +886,12 @@ Object subclass: #CartSession
poolDictionaries: '' poolDictionaries: ''
category: 'TusLibros'! category: 'TusLibros'!
!CartSession methodsFor: 'expiration' stamp: 'Castagna 7/21/2020 19:12:29'!
cart
^ cart.
! !
!CartSession methodsFor: 'expiration' stamp: 'Castagna 7/21/2020 18:01:41'! !CartSession methodsFor: 'expiration' stamp: 'Castagna 7/21/2020 18:01:41'!
isExpiredAt: aTime isExpiredAt: aTime
^ aTime > (lastUsedTime + interface sessionDuration). ^ aTime > (lastUsedTime + interface sessionDuration).
! ! ! !
!CartSession methodsFor: 'expiration' stamp: 'Castagna 7/21/2020 19:12:22'!
owner
^ owner.
! !
!CartSession methodsFor: 'initialization' stamp: 'Castagna 7/21/2020 17:44:54'! !CartSession methodsFor: 'initialization' stamp: 'Castagna 7/21/2020 17:44:54'!
initializeForCustomer: aUser with: aCart using: anInterface initializeForCustomer: aUser with: aCart using: anInterface
...@@ -895,6 +902,30 @@ initializeForCustomer: aUser with: aCart using: anInterface ...@@ -895,6 +902,30 @@ initializeForCustomer: aUser with: aCart using: anInterface
lastUsedTime _ anInterface clock currentTime. lastUsedTime _ anInterface clock currentTime.
! ! ! !
!CartSession methodsFor: 'reseting time' stamp: 'Castagna 7/23/2020 15:42:44'!
resetLastUsedTime
lastUsedTime _ interface clock currentTime.! !
!CartSession methodsFor: 'accessing' stamp: 'Castagna 7/21/2020 19:12:29'!
cart
^ cart.
! !
!CartSession methodsFor: 'accessing' stamp: 'Castagna 7/23/2020 15:43:03'!
lastUsedTime
^lastUsedTime! !
!CartSession methodsFor: 'accessing' stamp: 'Castagna 7/21/2020 19:12:22'!
owner
^ owner.
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'CartSession class' category: #TusLibros! !classDefinition: 'CartSession class' category: #TusLibros!
...@@ -1159,11 +1190,6 @@ initializeForCart: aCart ...@@ -1159,11 +1190,6 @@ initializeForCart: aCart
amountByItem _ (aCart items asBag) contents. amountByItem _ (aCart items asBag) contents.
total _ aCart total.! ! total _ aCart total.! !
!Sale methodsFor: 'initialization' stamp: 'HernanWilkinson 6/17/2013 18:47'!
initializeTotal: aTotal
total := aTotal ! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'Sale class' category: #TusLibros! !classDefinition: 'Sale class' category: #TusLibros!
...@@ -1207,10 +1233,10 @@ itemSellByTheStore ...@@ -1207,10 +1233,10 @@ itemSellByTheStore
^ 'validBook'! ! ^ 'validBook'! !
!StoreTestObjectsFactory methodsFor: 'items' stamp: 'HernanWilkinson 6/17/2013 18:08'! !StoreTestObjectsFactory methodsFor: 'items' stamp: 'Castagna 7/23/2020 16:09:30'!
itemSellByTheStorePrice itemSellByTheStorePrice
^10! ! ^10.! !
!StoreTestObjectsFactory methodsFor: 'cart' stamp: 'HernanWilkinson 6/17/2013 18:08'! !StoreTestObjectsFactory methodsFor: 'cart' stamp: 'HernanWilkinson 6/17/2013 18:08'!
...@@ -1265,7 +1291,7 @@ Object subclass: #TusLibrosSystemFacade ...@@ -1265,7 +1291,7 @@ Object subclass: #TusLibrosSystemFacade
poolDictionaries: '' poolDictionaries: ''
category: 'TusLibros'! category: 'TusLibros'!
!TusLibrosSystemFacade methodsFor: 'initialization' stamp: 'Castagna 7/21/2020 20:16:37'! !TusLibrosSystemFacade methodsFor: 'initialization' stamp: 'Castagna 7/23/2020 16:10:33'!
initializeWithValidUsersAndPasswords: aValidUsersAndPasswords using: aCatalog mesuringTimeWithClock: aClock debitingWith: aMerchantProcessor initializeWithValidUsersAndPasswords: aValidUsersAndPasswords using: aCatalog mesuringTimeWithClock: aClock debitingWith: aMerchantProcessor
validUsersAndPasswords _ aValidUsersAndPasswords. validUsersAndPasswords _ aValidUsersAndPasswords.
...@@ -1273,8 +1299,9 @@ initializeWithValidUsersAndPasswords: aValidUsersAndPasswords using: aCatalog me ...@@ -1273,8 +1299,9 @@ initializeWithValidUsersAndPasswords: aValidUsersAndPasswords using: aCatalog me
catalog _ aCatalog. catalog _ aCatalog.
lastId _ 0. lastId _ 0.
salesBook _ OrderedCollection new.
clock _ aClock. clock _ aClock.
salesBook _ OrderedCollection new.
cartSessions _ Dictionary new. cartSessions _ Dictionary new.
salesByUser _ Dictionary new.! ! salesByUser _ Dictionary new.! !
...@@ -1337,7 +1364,7 @@ createCartId ...@@ -1337,7 +1364,7 @@ createCartId
^ lastId.! ! ^ lastId.! !
!TusLibrosSystemFacade methodsFor: 'adding to cart' stamp: 'Castagna 7/21/2020 19:57:56'! !TusLibrosSystemFacade methodsFor: 'adding to cart' stamp: 'Castagna 7/23/2020 16:18:45'!
add: aQuantity of: aBook toCartWithId: aCartId add: aQuantity of: aBook toCartWithId: aCartId
| cart session | | cart session |
...@@ -1345,53 +1372,56 @@ add: aQuantity of: aBook toCartWithId: aCartId ...@@ -1345,53 +1372,56 @@ add: aQuantity of: aBook toCartWithId: aCartId
session _ cartSessions at: aCartId ifAbsent: [ self error: self class canNotAddItemToANotCreatedCartErrorMessage. ]. session _ cartSessions at: aCartId ifAbsent: [ self error: self class canNotAddItemToANotCreatedCartErrorMessage. ].
cart _ session cart. cart _ session cart.
(cart catalog keys includes: aBook) ifFalse: [ (session isExpiredAt: clock currentTime) ifTrue: [self error: self class sessionHasExpiredErrorMessage.].
self error: cart invalidItemErrorMessage.
].
(session isExpiredAt: clock currentTime) ifTrue:[
self error: self class sessionHasExpiredErrorMessage.
].
cart add: aQuantity of: aBook. cart add: aQuantity of: aBook.
! !
session resetLastUsedTime.! !
!TusLibrosSystemFacade methodsFor: 'list cart' stamp: 'Castagna 7/21/2020 19:42:22'! !TusLibrosSystemFacade methodsFor: 'list cart' stamp: 'Castagna 7/23/2020 16:31:41'!
listCartWithId: aCartId listCartWithId: aCartId
| cartItems session| | cartItems session|
(self isValidCartId: aCartId) ifFalse: [self error: self class invalidCartIdErrorMessage.]. self assertIsValidCartId: aCartId.
session _ cartSessions at: aCartId. session _ cartSessions at: aCartId.
self assertIsNotExpiredSession: session.
(session isExpiredAt: clock currentTime) ifTrue:[
self error: self class sessionHasExpiredErrorMessage.
].
cartItems _ session cart items asBag. cartItems _ session cart items asBag.
session resetLastUsedTime.
^ cartItems. ^ cartItems.
! ! ! !
!TusLibrosSystemFacade methodsFor: 'checkout' stamp: 'Castagna 7/21/2020 22:50:20'! !TusLibrosSystemFacade methodsFor: 'checkout' stamp: 'Castagna 7/23/2020 16:27:53'!
assertIsNotExpiredSession: aSession.
(aSession isExpiredAt: clock currentTime) ifTrue: [ self error: self class sessionHasExpiredErrorMessage ].
! !
!TusLibrosSystemFacade methodsFor: 'checkout' stamp: 'Castagna 7/23/2020 16:24:36'!
assertIsValidCartId: aCartId
(self isValidCartId: aCartId) ifFalse: [ self error: self class invalidCartIdErrorMessage ].
! !
!TusLibrosSystemFacade methodsFor: 'checkout' stamp: 'Castagna 7/23/2020 16:28:29'!
checkout: aCartId ownedBy: anOwner withCreditCardNumber: aCreditCardNumber withExpirationDate: anExpirationDate checkout: aCartId ownedBy: anOwner withCreditCardNumber: aCreditCardNumber withExpirationDate: anExpirationDate
| cart session creditCard today total cashier user userSales | | cart session creditCard today total cashier user userSales |
(self isValidCartId: aCartId) ifFalse: [ self error: self class invalidCartIdErrorMessage ]. self assertIsValidCartId: aCartId.
session _ cartSessions at: aCartId. session _ cartSessions at: aCartId.
self assertIsNotExpiredSession: session.
(session isExpiredAt: clock currentTime) ifTrue:[
self error: self class sessionHasExpiredErrorMessage.
].
cart _ session cart. cart _ session cart.
creditCard _ CreditCard withNumber: aCreditCardNumber ownedBy: anOwner expiringOn: anExpirationDate. creditCard _ CreditCard withNumber: aCreditCardNumber ownedBy: anOwner expiringOn: anExpirationDate.
today _ DateAndTime now. today _ DateAndTime now.
...@@ -1403,6 +1433,7 @@ checkout: aCartId ownedBy: anOwner withCreditCardNumber: aCreditCardNumber withE ...@@ -1403,6 +1433,7 @@ checkout: aCartId ownedBy: anOwner withCreditCardNumber: aCreditCardNumber withE
userSales add: self salesBook last. userSales add: self salesBook last.
salesByUser at: user put: userSales. salesByUser at: user put: userSales.
cartSessions removeKey: aCartId.
^ total. ^ total.
! ! ! !
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment