IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 3e6bf4ad authored by APalumbo97's avatar APalumbo97
Browse files

Adding unit tests for export stuff.

parent 4b0bcd0f
const { getAssetTypes } = require('../assetDefinitions.controller');
const { getAssetTypes, getAssetPropsByTypeID, getAssetPropTypes } = require('../assetDefinitions.controller');
const assetDefinitionsDb = require('../../db/assetDefinitions.db');
describe('assetDefinitions.controller.getAssetTypes', () => {
......@@ -27,6 +27,62 @@ describe('assetDefinitions.controller.getAssetTypes', () => {
});
});
describe('assetDefinitions.controller.getAssetPropsByTypeID', () => {
let req;
let res;
let next;
let expectedAssetTypes;
let data;
beforeEach(() => {
req = {
'body': {
}
};
res = {
json: jest.fn()
};
next = jest.fn();
expectedAssetTypes = [{}];
data = { rows: expectedAssetTypes };
assetDefinitionsDb.findAssetPropsByTypeID = jest.fn(async () => data);
});
it('returns all asset types in DB', async () => {
await getAssetPropsByTypeID(req, res, next);
expect(res.json).toHaveBeenCalledWith(data);
});
});
describe('assetDefinitions.controller.getAssetPropsTypes', () => {
let req;
let res;
let next;
let expectedAssetTypes;
let data;
beforeEach(() => {
req = {};
res = {
json: jest.fn()
};
next = jest.fn();
expectedAssetTypes = [{}];
data = { rows: expectedAssetTypes };
assetDefinitionsDb.findAssetPropTypes = jest.fn(async () => data);
});
it('returns all asset types in DB', async () => {
await getAssetPropTypes(req, res, next);
expect(res.json).toHaveBeenCalledWith(data);
});
});
describe('assetDefinitions.controller.storeCSV', () => {
let req;
let res;
......
......@@ -146,5 +146,42 @@ describe('assetDefinitions.db.storeCSV', () => {
global.dbPool.connect = jest.fn(async () => { return client; });
});
describe('assetDefinitions.db.findAssetTypes', () => {
let rows;
let query;
beforeEach(() => {
rows = [{}];
query = jest.fn(async() => rows);
global.dbPool = { query };
});
it('finds all asset types in the database', async () => {
const actualRows = await findAssetTypes();
expect(actualRows).toEqual(rows);
});
});
describe('assetDefinitions.db.findAssetPropByTypeID', () => {
let rows;
let query;
let assetTypeId;
beforeEach(() => {
rows = [{}];
query = jest.fn(async() => rows);
global.dbPool = { query };
assetTypeId = 1;
});
it('finds all properties associated with the asset type ID given', async () => {
const actualRows = await findAssetPropTypes(assetTypeId);
expect(actualRows).toEqual(rows);
});
});
// TODO tests for storeCSV function
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment