Advertisement
petur_stoqnov

Untitled

Feb 14th, 2021
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let { Repository } = require("./solution.js");
  2. /*describe("Tests …", function () {
  3.     describe("TODO …", function () {
  4.         it("TODO …", function () {
  5.             // TODO: …
  6.         });
  7.     });
  8.     // TODO: …
  9. });*/
  10. const assert = require('chai').assert;
  11. const mocha = require('mocha');
  12. describe('class Repository', () => {
  13.     it('Test initializing', () => {
  14.         let properties = {
  15.             name: "string",
  16.             age: "number",
  17.             birthday: "object"
  18.         };
  19.         let repository = new Repository(properties)
  20.         assert.notEqual(repository, undefined);
  21.         assert.instanceOf(repository, Repository);
  22.     });
  23.     it('Test count', () => {
  24.         let properties2 = {
  25.             name: "string",
  26.             age: "number",
  27.             birthday: "object"
  28.         };
  29.         let entity = {
  30.             name: "Pesho",
  31.             age: 22,
  32.             birthday: new Date(1998, 0, 7)
  33.         };
  34.         let entity2 = {
  35.             name: "Pesho2",
  36.             age: 22,
  37.             birthday: new Date(1998, 0, 7)
  38.         };
  39.         let repo1 = new Repository(properties2)
  40.         repo1.add(entity)
  41.         repo1.add(entity2)
  42.         assert.equal(repo1.count, 2)
  43.         repo1.del(0);
  44.         assert.equal(repo1.count, 1)
  45.         repo1.del(1);
  46.         assert.equal(repo1.count, 0)
  47.     });
  48.     it('Test add', () => {
  49.         let properties3 = {
  50.             name: "string",
  51.             age: "number",
  52.             birthday: "object"
  53.         };
  54.         let entity = {
  55.             name: "Pesho",
  56.             age: 22,
  57.             birthday: new Date(1998, 0, 7)
  58.         };
  59.         let entity2 = {
  60.             name: "Pesho2",
  61.             age: 22,
  62.             birthday: new Date(1998, 0, 7)
  63.         };
  64.         let repo1 = new Repository(properties3)
  65.         repo1.add(entity)
  66.         assert.equal(repo1.add(entity2), 1)
  67.         assert.equal(repo1.count, 2)
  68.     });
  69.     it('Test getId', () => {
  70.         let properties4 = {
  71.             name: "string",
  72.             age: "number",
  73.             birthday: "object"
  74.         };
  75.         let entity = {
  76.             name: "Pesho",
  77.             age: 22,
  78.             birthday: new Date(1998, 0, 7)
  79.         };
  80.         let repo4 = new Repository(properties4)
  81.         assert.throw(()=>{repo4.getId(1)}, "Entity with id: 1 does not exist!")
  82.         repo4.add(entity)
  83.         assert.equal(JSON.stringify(repo4.getId(0)) === JSON.stringify(entity), true)
  84.     });
  85.     it('Test update', () => {
  86.         let properties5 = {
  87.             name: "string",
  88.             age: "number",
  89.             birthday: "object"
  90.         };
  91.         let entity5 = {
  92.             name: "Pesho",
  93.             age: 22,
  94.             birthday: new Date(1998, 0, 7)
  95.         };let entity5Second = {
  96.             name: "Pesho2",
  97.             age: 22,
  98.             birthday: new Date(1998, 0, 7)
  99.         };
  100.         let entity5Second2 = {
  101.             name: 8,
  102.             age: 22,
  103.             birthday: new Date(1998, 0, 7)
  104.         };
  105.         let repo5 = new Repository(properties5)
  106.         assert.throw(()=>{repo5.update(1, entity5Second)}, 'Entity with id: 1 does not exist!')
  107.         repo5.add(entity5);
  108.         repo5.update(0, entity5Second)
  109.         assert.throw(()=>{repo5.update(0, entity5Second2)}, 'Property name is not of correct type!')
  110.         assert.equal(JSON.stringify(repo5.getId(0)) === JSON.stringify(entity5Second), true)
  111.     });
  112.     it('Test del', () => {
  113.         let properties6 = {
  114.             name: "string",
  115.             age: "number",
  116.             birthday: "object"
  117.         };
  118.         let entity6 = {
  119.             name: "Pesho",
  120.             age: 22,
  121.             birthday: new Date(1998, 0, 7)
  122.         };
  123.         let repo6 = new Repository(properties6)
  124.         assert.throw(()=>{repo6.del(0)}, "Entity with id: 0 does not exist!")
  125.         assert.equal(repo6.count, 0)
  126.         repo6.add(entity6)
  127.         assert.equal(repo6.count, 1)
  128.     });
  129.     it('Test _validate', () => {
  130.         let properties7 = {
  131.             name: "string",
  132.             age: "number",
  133.             birthday: "object"
  134.         };
  135.         let entity7 = {
  136.             asd: "Pesho",
  137.             age: 22,
  138.             birthday: new Date(1998, 0, 7)
  139.         };
  140.         let entity8 = {
  141.             name: 'Pesho',
  142.             age: 18,
  143.             birthday:  2
  144.         };
  145.         let entity9 = {
  146.             name: 'Pesho',
  147.             age: 'asd',
  148.             birthday:  new Date(1998, 0, 7)
  149.         };
  150.         let repo7 = new Repository(properties7)
  151.         assert.throw(()=>{repo7.add(entity7)}, 'Property name is missing from the entity!')
  152.         assert.throw(()=>{repo7.add(entity8)}, 'Property birthday is not of correct type!')
  153.         assert.throw(()=>{repo7.add(entity9)}, 'Property age is not of correct type!')
  154.     });
  155. });
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement