ven.spec.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. const { expect } = require('chai');
  3. const { sequelize, Ven } = require('../../../db');
  4. const { v4 } = require('uuid');
  5. describe('VEN Model', function() {
  6. before(async () => {
  7. await sequelize.sync();
  8. });
  9. describe('Retrieval', function() {
  10. it('returns no results for unknown ven_id', async () => {
  11. const randomVenId = v4();
  12. const existing = await Ven.findOne({ where: { ven_id: randomVenId } });
  13. expect(existing).to.be.null;
  14. });
  15. it('retrieves a saved record when queried by ven_id', async () => {
  16. const randomVenId = v4();
  17. const randomCommonName = v4();
  18. const ven = new Ven();
  19. ven.ven_id = randomVenId;
  20. ven.common_name = randomCommonName;
  21. await ven.save();
  22. const existing = await Ven.findOne({ where: { ven_id: randomVenId } });
  23. expect(existing).to.not.be.undefined;
  24. expect(existing.common_name).to.eql(randomCommonName);
  25. });
  26. it('retrieves a saved record when queried by common_name', async () => {
  27. const randomVenId = v4();
  28. const randomCommonName = v4();
  29. const ven = new Ven();
  30. ven.ven_id = randomVenId;
  31. ven.common_name = randomCommonName;
  32. await ven.save();
  33. const existing = await Ven.findOne({ where: { common_name: randomCommonName } });
  34. expect(existing).to.not.be.undefined;
  35. expect(existing.common_name).to.eql(randomCommonName);
  36. });
  37. });
  38. });