Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let { Repository } = require("./solution.js");
- /*describe("Tests …", function () {
- describe("TODO …", function () {
- it("TODO …", function () {
- // TODO: …
- });
- });
- // TODO: …
- });*/
- const assert = require('chai').assert;
- const mocha = require('mocha');
- describe('class Repository', () => {
- it('Test initializing', () => {
- let properties = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let repository = new Repository(properties)
- assert.notEqual(repository, undefined);
- assert.instanceOf(repository, Repository);
- });
- it('Test count', () => {
- let properties2 = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let entity = {
- name: "Pesho",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let entity2 = {
- name: "Pesho2",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let repo1 = new Repository(properties2)
- repo1.add(entity)
- repo1.add(entity2)
- assert.equal(repo1.count, 2)
- repo1.del(0);
- assert.equal(repo1.count, 1)
- repo1.del(1);
- assert.equal(repo1.count, 0)
- });
- it('Test add', () => {
- let properties3 = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let entity = {
- name: "Pesho",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let entity2 = {
- name: "Pesho2",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let repo1 = new Repository(properties3)
- repo1.add(entity)
- assert.equal(repo1.add(entity2), 1)
- assert.equal(repo1.count, 2)
- });
- it('Test getId', () => {
- let properties4 = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let entity = {
- name: "Pesho",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let repo4 = new Repository(properties4)
- assert.throw(()=>{repo4.getId(1)}, "Entity with id: 1 does not exist!")
- repo4.add(entity)
- assert.equal(JSON.stringify(repo4.getId(0)) === JSON.stringify(entity), true)
- });
- it('Test update', () => {
- let properties5 = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let entity5 = {
- name: "Pesho",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };let entity5Second = {
- name: "Pesho2",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let entity5Second2 = {
- name: 8,
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let repo5 = new Repository(properties5)
- assert.throw(()=>{repo5.update(1, entity5Second)}, 'Entity with id: 1 does not exist!')
- repo5.add(entity5);
- repo5.update(0, entity5Second)
- assert.throw(()=>{repo5.update(0, entity5Second2)}, 'Property name is not of correct type!')
- assert.equal(JSON.stringify(repo5.getId(0)) === JSON.stringify(entity5Second), true)
- });
- it('Test del', () => {
- let properties6 = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let entity6 = {
- name: "Pesho",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let repo6 = new Repository(properties6)
- assert.throw(()=>{repo6.del(0)}, "Entity with id: 0 does not exist!")
- assert.equal(repo6.count, 0)
- repo6.add(entity6)
- assert.equal(repo6.count, 1)
- });
- it('Test _validate', () => {
- let properties7 = {
- name: "string",
- age: "number",
- birthday: "object"
- };
- let entity7 = {
- asd: "Pesho",
- age: 22,
- birthday: new Date(1998, 0, 7)
- };
- let entity8 = {
- name: 'Pesho',
- age: 18,
- birthday: 2
- };
- let entity9 = {
- name: 'Pesho',
- age: 'asd',
- birthday: new Date(1998, 0, 7)
- };
- let repo7 = new Repository(properties7)
- assert.throw(()=>{repo7.add(entity7)}, 'Property name is missing from the entity!')
- assert.throw(()=>{repo7.add(entity8)}, 'Property birthday is not of correct type!')
- assert.throw(()=>{repo7.add(entity9)}, 'Property age is not of correct type!')
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement