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
poolDictionaries: ''
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
self
should: [ interface add: 3 of: 'book1' toCartWithId: invalidCartId . ]
......@@ -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
| cartId cart session |
cartId _ interface createCartFor: 'user1' with: 'pass1'.
session _ interface cartSessions at: cartId.
cart _ session cart.
......@@ -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'!
validUsersAndPasswords
......@@ -383,7 +399,6 @@ validUsersAndPasswords
! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart creation' stamp: 'Castagna 7/21/2020 23:42:14'!
test01CannotCreateCartWithInvalidUser
......@@ -401,30 +416,22 @@ test01CannotCreateCartWithInvalidUser
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
| aUser aPassword |
aUser _ 'user3'.
aPassword _ 'pass4'.
self
should: [ interface createCartFor: aUser with: aPassword.]
should: [ interface createCartFor: 'user3' with: 'pass4'.]
raise: Error - MessageNotUnderstood
withExceptionDo: [ :anError |
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
| aUser aPassword cartId |
aUser _ 'user3'.
aPassword _ 'pass3'.
| cartId |
cartId _ interface createCartFor: aUser with: aPassword.
cartId _ interface createCartFor: 'user3' with: 'pass3'.
self assert: interface cartSessions keys includes: cartId.
! !
......@@ -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
| cartId cart session |
cartId _ interface createCartFor: 'user1' with: 'pass1'.
cartId _ interface createCartFor: 'user3' with: 'pass3'.
session _ interface cartSessions at: cartId.
cart _ session cart.
cart add: 2 of: 'validBook'.
self
should: [ interface listPurchasesOfUser: 'user4' withPassword: 'pass4']
should: [ interface listPurchasesOfUser: 'user3' withPassword: 'pass4']
raise: Error - MessageNotUnderstood
withExceptionDo: [
:anError |
......@@ -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
| cartId cart session |
cartId _ interface createCartFor: 'user1' with: 'pass1'.
session _ interface cartSessions at: cartId.
cart _ session cart.
cart add: 2 of: 'validBook'.
self
should: [ interface listPurchasesOfUser: 'user1' withPassword: 'pass4']
should: [ interface listPurchasesOfUser: 'user4' withPassword: 'pass2']
raise: Error - MessageNotUnderstood
withExceptionDo: [
:anError |
......@@ -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
| cartId cart total session debitedAmount debitedCreditCard |
......@@ -607,12 +606,11 @@ test12CanCheckoutACartCorrectly
self assert: debitedCreditCard number equals: validCardNumber.
self assert: debitedCreditCard expiration equals: expirationDate.
self assert: debitedAmount = total.
! !
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/21/2020 23:42:14'!
test13CanNotCheckoutWithAnInvalidCreditCart
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/23/2020 16:03:18'!
test13CanNotCheckoutWithAnInvalidCreditCard
| cartId cart session |
......@@ -628,7 +626,7 @@ test13CanNotCheckoutWithAnInvalidCreditCart
withExceptionDo: [
:anError | self assert: anError messageText equals: CreditCard invalidCreditCardNumberErrorMessage.
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.
].
......@@ -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
| cartId |
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).
......@@ -655,8 +653,8 @@ test20CanNotCheckoutCartIfSessionHasExpired
].
! !
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/21/2020 23:42:14'!
test21CartShouldBeEmptyAfterCheckout
!TusLibrosSystemFacadeTest methodsFor: 'test - checkout' stamp: 'Castagna 7/23/2020 15:44:38'!
test23CheckoutClosesCartSession
| cartId cart session debitedAmount debitedCreditCard |
......@@ -673,26 +671,31 @@ test21CartShouldBeEmptyAfterCheckout
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
self
should: [ interface listCartWithId: invalidCartId. ]
raise: Error - MessageNotUnderstood
withExceptionDo: [
:anError |
self assert: anError messageText equals: interface class invalidCartIdErrorMessage.
].
withExceptionDo: [ :anError | self assert: anError messageText equals: interface class invalidCartIdErrorMessage. ].
! !
!TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/21/2020 23:42:14'!
test08ListingAnEmptyCartShowsAnEmptyDictionary
!TusLibrosSystemFacadeTest methodsFor: 'test - cart listing' stamp: 'Castagna 7/23/2020 16:04:54'!
test08ListingAnEmptyCartShowsAnEmptyBag
| cartId |
......@@ -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
| cartId |
......@@ -736,11 +739,27 @@ test19CanNotListCartItemsIfSessionHasExpired
should: [ interface listCartWithId: cartId ]
raise: Error - MessageNotUnderstood
withExceptionDo: [
:anError |
self assert: anError messageText equals: interface class sessionHasExpiredErrorMessage .
:anError | 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'!
......@@ -867,24 +886,12 @@ Object subclass: #CartSession
poolDictionaries: ''
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'!
isExpiredAt: aTime
^ 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'!
initializeForCustomer: aUser with: aCart using: anInterface
......@@ -895,6 +902,30 @@ initializeForCustomer: aUser with: aCart using: anInterface
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!
......@@ -1159,11 +1190,6 @@ initializeForCart: aCart
amountByItem _ (aCart items asBag) contents.
total _ aCart total.! !
!Sale methodsFor: 'initialization' stamp: 'HernanWilkinson 6/17/2013 18:47'!
initializeTotal: aTotal
total := aTotal ! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!classDefinition: 'Sale class' category: #TusLibros!
......@@ -1207,10 +1233,10 @@ itemSellByTheStore
^ 'validBook'! !
!StoreTestObjectsFactory methodsFor: 'items' stamp: 'HernanWilkinson 6/17/2013 18:08'!
!StoreTestObjectsFactory methodsFor: 'items' stamp: 'Castagna 7/23/2020 16:09:30'!
itemSellByTheStorePrice
^10! !
^10.! !
!StoreTestObjectsFactory methodsFor: 'cart' stamp: 'HernanWilkinson 6/17/2013 18:08'!
......@@ -1265,7 +1291,7 @@ Object subclass: #TusLibrosSystemFacade
poolDictionaries: ''
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
validUsersAndPasswords _ aValidUsersAndPasswords.
......@@ -1273,8 +1299,9 @@ initializeWithValidUsersAndPasswords: aValidUsersAndPasswords using: aCatalog me
catalog _ aCatalog.
lastId _ 0.
salesBook _ OrderedCollection new.
clock _ aClock.
salesBook _ OrderedCollection new.
cartSessions _ Dictionary new.
salesByUser _ Dictionary new.! !
......@@ -1337,7 +1364,7 @@ createCartId
^ 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
| cart session |
......@@ -1345,53 +1372,56 @@ add: aQuantity of: aBook toCartWithId: aCartId
session _ cartSessions at: aCartId ifAbsent: [ self error: self class canNotAddItemToANotCreatedCartErrorMessage. ].
cart _ session cart.
(cart catalog keys includes: aBook) ifFalse: [
self error: cart invalidItemErrorMessage.
].
(session isExpiredAt: clock currentTime) ifTrue:[
self error: self class sessionHasExpiredErrorMessage.
].
(session isExpiredAt: clock currentTime) ifTrue: [self error: self class sessionHasExpiredErrorMessage.].
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
| cartItems session|
(self isValidCartId: aCartId) ifFalse: [self error: self class invalidCartIdErrorMessage.].
self assertIsValidCartId: aCartId.
session _ cartSessions at: aCartId.
(session isExpiredAt: clock currentTime) ifTrue:[
self error: self class sessionHasExpiredErrorMessage.
].
self assertIsNotExpiredSession: session.
cartItems _ session cart items asBag.
session resetLastUsedTime.
^ 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
| 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 isExpiredAt: clock currentTime) ifTrue:[
self error: self class sessionHasExpiredErrorMessage.
].
self assertIsNotExpiredSession: session.
cart _ session cart.
creditCard _ CreditCard withNumber: aCreditCardNumber ownedBy: anOwner expiringOn: anExpirationDate.
today _ DateAndTime now.
......@@ -1403,6 +1433,7 @@ checkout: aCartId ownedBy: anOwner withCreditCardNumber: aCreditCardNumber withE
userSales add: self salesBook last.
salesByUser at: user put: userSales.
cartSessions removeKey: aCartId.
^ 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