/ test / contract_spec.js
contract_spec.js
 1  
 2  // our contract object to test
 3  const DReddit = embark.require('Embark/contracts/DReddit');
 4  
 5  // variables that will be updated in the tests
 6  let accounts;
 7  let postId;
 8  
 9  // set up our config test parameters
10  config({
11    contracts: {
12      DReddit: {
13        // would pass constructor args here if needed
14      }
15    }
16  }, (err, theAccounts) => {
17    // this is the list of accounts our node / wallet controls.
18    accounts = theAccounts;
19  });
20  
21  // other test parameters
22  const ipfsHash = 'Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z';
23  
24  // Embark exposes a global contract method as an alias
25  // for Mocha.describe
26  contract("DReddit contract", function () {
27  
28    this.timeout(0);
29  
30    it("should be able to create a post and receive it via contract event", async function () {    
31      // TODO: 
32    });
33  
34    it("post should have correct data", async function (){
35      // TODO: 
36    });
37  
38    it("one post should be registered", async function () {
39      const n = await DReddit.methods.numPosts().call();
40      assert.equal(n, 1);
41    });
42  
43    it("should not be able to vote in an unexisting post", async function () {
44      const userCanVote = await DReddit.methods.canVote("123").call();
45      assert.equal(userCanVote, false);
46    });
47  
48    it("should be able to vote in a post if account hasn't voted before", async function () {
49      const userCanVote = await DReddit.methods.canVote(postId).call();
50      assert.equal(userCanVote, true);
51    });
52  
53    it("should be able to vote in a post", async function () {
54      const receipt = await DReddit.methods.vote(postId, 1).send();
55      const Vote = receipt.events.Vote;
56      assert.equal(Vote.returnValues.voter, accounts[0]);
57    });
58  
59    it("should't be able to vote twice", async function () {
60      // TODO: 
61    });
62  
63  });