Skip to content

Commit

Permalink
Updated add to cart test for smart contract
Browse files Browse the repository at this point in the history
  • Loading branch information
riadelimemmedov committed Mar 19, 2024
1 parent 74c1e6b commit d0de454
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions blockchain/test/PetAdoption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,36 @@ describe("PetAdoption", function () {
const {account2,contract} = await loadFixture(deployContractFixture)

const pet_id = 1
const pet_slug = "rex_1"
const pet_name = "Rex"
const pet_color = "red"
const pet_price = 100
const pet_photo = "https://images.unsplash.com/photo-1600682011352-e448301668e7?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1348&q=40"

expect(account2).not.be.null
await expect(contract.addToCart(pet_id,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted
await expect(contract.addToCart(pet_id,pet_slug,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted
expect(contract.getCartItems()).not.be.null
})
it("should match added and returned pet",async function(){
const {account2,contract} = await loadFixture(deployContractFixture)


const pet_id = 1
const pet_slug = "rex_1"
const pet_name = "Rex"
const pet_color = "red"
const pet_price = 100
const pet_photo = "https://images.unsplash.com/photo-1600682011352-e448301668e7?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1348&q=40"

await expect(contract.connect(account2)).not.to.be.reverted
await expect(contract.connect(account2).addToCart(pet_id, pet_name, pet_color, pet_price, pet_photo)).not.to.be.reverted
await expect(contract.connect(account2).addToCart(pet_id,pet_slug,pet_name, pet_color, pet_price, pet_photo)).not.to.be.reverted

const cartItems = await contract.connect(account2).getCartItems()

expect(account2).not.be.null
expect(cartItems.length).to.be.equal(1)
expect(cartItems[0].id).to.be.equal(pet_id)
expect(cartItems[0].slug).to.be.equal(pet_slug)
expect(cartItems[0].name).to.be.equal(pet_name)
expect(cartItems[0].color).to.be.equal(pet_color)
expect(cartItems[0].price).to.be.equal(pet_price)
Expand All @@ -133,15 +137,16 @@ describe("PetAdoption", function () {
const {account2,contract} = await loadFixture(deployContractFixture)

const pet_id = 1
const pet_slug = "rex_1"
const pet_name = "Rex"
const pet_color = "red"
const pet_price = 100
const pet_photo = "https://images.unsplash.com/photo-1600682011352-e448301668e7?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1348&q=40"

expect(account2).not.be.null
await expect(contract.addToCart(pet_id,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted // 0 index
await expect(contract.addToCart(pet_id,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted // 1 index
await expect(contract.addToCart(pet_id,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted// 2 index
await expect(contract.addToCart(pet_id,pet_slug,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted // 0 index
await expect(contract.addToCart(pet_id,pet_slug,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted // 1 index
await expect(contract.addToCart(pet_id,pet_slug,pet_name,pet_color,pet_price,pet_photo)).not.to.be.reverted// 2 index
expect(contract.getCartItems()).not.be.null

expect(await contract.getCartLength().then(value => parseInt(value.toString()))).equal(3)
Expand Down

0 comments on commit d0de454

Please sign in to comment.