github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/blockapps-ba-master/server/lib/project/test/project.test.js (about)

     1  require('co-mocha');
     2  const ba = require('blockapps-rest');
     3  const rest = ba.rest;
     4  const common = ba.common;
     5  const config = common.config;
     6  const util = common.util;
     7  const should = common.should;
     8  const assert = common.assert;
     9  const Promise = common.Promise;
    10  
    11  const projectJs = require('../project');
    12  
    13  const adminName = util.uid('Admin');
    14  const adminPassword = '1234';
    15  
    16  describe('Project tests', function() {
    17    this.timeout(config.timeout);
    18  
    19    let admin;
    20  
    21    before(function* () {
    22      admin = yield rest.createUser(adminName, adminPassword);
    23    });
    24  
    25    /**
    26    {
    27        created: '2017-05-09T16:47:49.016Z',
    28        buyer: 'buyer1',
    29        name: 'T-Shirts with logo',
    30        description: 'The T-Shirts with our company\'s logo on the chest, Qty: 50',
    31        priceDesired: 800.10,
    32        desiredDeliveryDate: '2017-05-20T16:47:49.016Z',
    33        addressStreet: '109 S 5th street',
    34        addresscity: 'Brooklyn',
    35        addressstate: 'New York',
    36        addresszip: '11249',
    37        spec: 'Lorem ipsum dolor sit amet, eam molestie singulis referrentur',
    38        state: 'OPEN',
    39        deliveredDate: null // filled when the 'RECEIVED' button clicked
    40  
    41        string public name;
    42        string public buyer;
    43        string public description;
    44        string public spec;
    45        uint public price; // in cents
    46  
    47        uint public created; // date
    48        uint public targetDelivery; // date
    49        uint public delivered; // date
    50  
    51        string public addressStreet;
    52        string public addressCity;
    53        string public addressState;
    54        string public addressZip;
    55  
    56      }
    57      */
    58  
    59    it('Create Contract', function* () {
    60      const name = util.uid('Project ? % # ');
    61      const buyer = 'Buyer1 ? % # ';
    62      const description = 'description ? % # ';
    63      const spec = 'spec ? % # ';
    64      const price = 1234;
    65  
    66      const created = new Date().getTime();
    67      const targetDelivery = created + 3 * 24*60*60*1000; // 3 days
    68  
    69      const addressStreet = 'addressStreet';
    70      const addressCity = 'addressCity';
    71      const addressState = 'addressState';
    72      const addressZip = 'addressZip';
    73  
    74      const args = {
    75        _name: name,
    76        _buyer: buyer,
    77        _description: description,
    78        _spec: spec,
    79        _price: price,
    80  
    81        _created: created,
    82        _targetDelivery: targetDelivery,
    83  
    84        // _addressStreet: addressStreet,
    85        // _addressCity: addressCity,
    86        // _addressState: addressState,
    87        // _addressZip: addressZip,
    88      };
    89  
    90      const contract = yield projectJs.uploadContract(admin, args);
    91      // state
    92      {
    93        const project = yield contract.getState();
    94        assert.equal(project.name, name, 'name');
    95        assert.equal(project.buyer, buyer, 'buyer');
    96        assert.equal(project.description, description, 'description');
    97        assert.equal(project.spec, spec, 'spec');
    98        assert.equal(project.price, price, 'price');
    99        assert.equal(project.created, created, 'created');
   100        assert.equal(project.targetDelivery, targetDelivery, 'targetDelivery');
   101      }
   102      // query
   103      {
   104        const project = yield projectJs.getProjectByName(name);
   105        assert.equal(project.name, name, 'name');
   106        assert.equal(project.buyer, buyer, 'buyer');
   107        assert.equal(project.description, description, 'description');
   108        assert.equal(project.spec, spec, 'spec');
   109        assert.equal(project.price, price, 'price');
   110        assert.equal(project.created, created, 'created');
   111        assert.equal(project.targetDelivery, targetDelivery, 'targetDelivery');
   112      }
   113  
   114    });
   115  });