Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Sebastián Arias
tps-ing1-1c-2020
Commits
16c0b66c
Commit
16c0b66c
authored
4 years ago
by
Franco Nicolas Castagna
Browse files
Options
Download
Email Patches
Plain Diff
Corregimos algunas cosas
parent
22050353
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
95 deletions
+126
-95
20-MisLibros/Iteracion 3/TusLibros.st
20-MisLibros/Iteracion 3/TusLibros.st
+126
-95
No files found.
20-MisLibros/Iteracion 3/TusLibros.st
View file @
16c0b66c
...
...
@@ -297,9 +297,8 @@ TestCase subclass: #TusLibrosSystemFacadeTest
poolDictionaries:
''
category:
'TusLibros'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart adding'
stamp:
'Castagna 7/2
1
/2020
23:42
:1
4
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart adding'
stamp:
'Castagna 7/2
3
/2020
15:51
:1
8
'
!
test04CanNotAddItemsToANotCreatedCart
self
should:
[
interface
add:
3
of:
'book1'
toCartWithId:
invalidCartId
.
]
...
...
@@ -328,13 +327,12 @@ test05CanAddItemsToACreatedCart
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart adding'
stamp:
'Castagna 7/2
1
/2020
23:42:14
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart adding'
stamp:
'Castagna 7/2
3
/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/2
1
/2020
23:42:14
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart creation'
stamp:
'Castagna 7/2
3
/2020
15:50:59
'
!
test02CannotCreateCartWithInvalidPassword
|
aUser aPassword
|
aUser
_
'user3'
.
aPassword
_
'pass4'
.
self
should:
[
interface
createCartFor:
aU
ser
with:
aP
ass
word
.]
should:
[
interface
createCartFor:
'u
ser
3'
with:
'p
ass
4'
.]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
self
assert:
anError
messageText
=
TusLibrosSystemFacade
invalidUserAndOrPasswordErrorMessage
.
]
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart creation'
stamp:
'Castagna 7/2
1
/2020
23:42:15
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart creation'
stamp:
'Castagna 7/2
3
/2020
15:50:23
'
!
test03CanCreateCartWithValidUserAndPassword
|
aUser aPassword cartId
|
aUser
_
'user3'
.
aPassword
_
'pass3'
.
|
cartId
|
cartId
_
interface
createCartFor:
aU
ser
with:
aP
ass
word
.
cartId
_
interface
createCartFor:
'u
ser
3'
with:
'p
ass
3'
.
self
assert:
interface
cartSessions
keys
includes:
cartId
.
! !
...
...
@@ -452,19 +459,19 @@ setUp
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - list purchases'
stamp:
'Castagna 7/2
1
/2020
23:42:15
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - list purchases'
stamp:
'Castagna 7/2
3
/2020
15:54:33
'
!
test14CanNotListPurchasesWithInvalidPassword
|
cartId cart session
|
cartId
_
interface
createCartFor:
'user
1
'
with:
'pass
1
'
.
cartId
_
interface
createCartFor:
'user
3
'
with:
'pass
3
'
.
session
_
interface
cartSessions
at:
cartId
.
cart
_
session
cart
.
cart
add:
2
of:
'validBook'
.
self
should:
[
interface
listPurchasesOfUser:
'user
4
'
withPassword:
'pass4'
]
should:
[
interface
listPurchasesOfUser:
'user
3
'
withPassword:
'pass4'
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
...
...
@@ -478,19 +485,11 @@ test14CanNotListPurchasesWithInvalidPassword
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - list purchases'
stamp:
'Castagna 7/2
1
/2020
23:42:14
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - list purchases'
stamp:
'Castagna 7/2
3
/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:
'user
1
'
withPassword:
'pass
4
'
]
should:
[
interface
listPurchasesOfUser:
'user
4
'
withPassword:
'pass
2
'
]
raise:
Error
-
MessageNotUnderstood
withExceptionDo:
[
:
anError
|
...
...
@@ -583,7 +582,7 @@ test11CanNotCheckoutAnEmptyCart
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - checkout'
stamp:
'Castagna 7/2
1
/2020
23:42
:1
4
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - checkout'
stamp:
'Castagna 7/2
3
/2020
15:58
:1
8
'
!
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/2
1
/2020
23:42
:1
4
'
!
test13CanNotCheckoutWithAnInvalidCreditCar
t
!
TusLibrosSystemFacadeTest
methodsFor:
'test - checkout'
stamp:
'Castagna 7/2
3
/2020
16:03
:1
8
'
!
test13CanNotCheckoutWithAnInvalidCreditCar
d
|
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
i
ncludes
:
'validBook'
.
self
assert:
(
cart
i
tems
occurrencesOf
:
'validBook'
)
equals:
3
.
self
assert:
cart
items
size
equals:
3
.
].
...
...
@@ -636,13 +634,13 @@ test13CanNotCheckoutWithAnInvalidCreditCart
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - checkout'
stamp:
'Castagna 7/2
1
/2020
23:42:14
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - checkout'
stamp:
'Castagna 7/2
3
/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/2
1
/2020
23:42:14
'
!
test2
1CartShouldBeEmptyAfterCheckout
!
TusLibrosSystemFacadeTest
methodsFor:
'test - checkout'
stamp:
'Castagna 7/2
3
/2020
15:44:38
'
!
test2
3CheckoutClosesCartSession
|
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/2
1
/2020
23:42:14
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart listing'
stamp:
'Castagna 7/2
3
/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/2
1
/2020
23:42:1
4'
!
test08ListingAnEmptyCartShowsAnEmpty
Dictionary
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart listing'
stamp:
'Castagna 7/2
3
/2020
16:04:5
4'
!
test08ListingAnEmptyCartShowsAnEmpty
Bag
|
cartId
|
...
...
@@ -722,7 +725,7 @@ test09ListingACartShowsCartItemsCorrectly
! !
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart listing'
stamp:
'Castagna 7/2
1
/2020
23:42
:1
4
'
!
!
TusLibrosSystemFacadeTest
methodsFor:
'test - cart listing'
stamp:
'Castagna 7/2
3
/2020
16:05
:1
6
'
!
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
/20
13
1
8
:0
8
'
!
!
StoreTestObjectsFactory
methodsFor:
'items'
stamp:
'
Castagna 7/23
/20
20
1
6
:0
9: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/2
1
/2020
20:16:37
'
!
!
TusLibrosSystemFacade
methodsFor:
'initialization'
stamp:
'Castagna 7/2
3
/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/2
1
/2020 1
9:57:56
'
!
!
TusLibrosSystemFacade
methodsFor:
'adding to cart'
stamp:
'Castagna 7/2
3
/2020 1
6: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/2
1
/2020 1
9:42:22
'
!
!
TusLibrosSystemFacade
methodsFor:
'list cart'
stamp:
'Castagna 7/2
3
/2020 1
6: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
i
sValidCartId:
aCartId
)
ifFalse:
[
self
error:
self
class
invalidCartIdErrorMessage
]
.
self
assertI
sValidCartId:
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
.
! !
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment