const { ethers } = require("hardhat");
const { expect } = require("chai");
describe("PlatziFood", () => {
const setup = async () => {
const accounts = await ethers.getSigners();
const PlatziFood = await ethers.getContractFactory("PlatziFood");
const deployed = await PlatziFood.deploy();
return {
accounts,
deployed,
};
};
describe("PlatziFood Contract", () => {
it("getAllPlatziFoods return an empty PlatziFoodItem[]", async () => {
const { deployed } = await setup();
expect(await deployed.getAllPlatziFoods()).to.eql([]);
});
it("addPlatziPunk added correctly and array in platziFoods", async () => {
const { deployed, accounts } = await setup();
const signer = accounts[0].address;
const foodUrl = "test";
const foodName = "Pollito";
const originCountry = "CO";
await deployed.addPlatziFood(foodUrl, foodName, originCountry);
expect(await deployed.getAllPlatziFoods()).to.eql([
[signer, foodUrl, foodName, originCountry],
]);
});
describe("getPlatziFoodByOwner", async () => {
it("should return all platzi food by owner", async () => {
const { deployed } = await setup();
const foodUrl = "test";
const foodName = "Pollito";
const originCountry = "CO";
await deployed.addPlatziFood(foodUrl, foodName, originCountry);
// ==============================
const foodUrl2 = "test";
const foodName2 = "Carnita";
const originCountry2 = "VE";
await deployed.addPlatziFood(foodUrl2, foodName2, originCountry2);
// ==============================
const getAllFoodsByMainSigner = await deployed.getPlatziFoodsByOwner();
expect(getAllFoodsByMainSigner.length).to.equal(2);
});
it("should return all platzi food by another address", async () => {
const { accounts, deployed } = await setup();
const signer = accounts[1];
const foodUrl = "test";
const foodName = "Carnita";
const originCountry = "VE";
await deployed
.connect(signer)
.addPlatziFood(foodUrl, foodName, originCountry);
expect(
await deployed.connect(signer).getPlatziFoodsByOwner()
).to.have.lengthOf(1);
});
});
});
});
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.