define.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var assert = require('assert');
  2. var _ = require('@sailshq/lodash');
  3. var Adapter = require('../../../lib/adapter');
  4. var Support = require('../../support/bootstrap');
  5. describe('Unit Tests ::', function() {
  6. describe('Define', function() {
  7. // Test Setup
  8. before(function(done) {
  9. Support.registerConnection(['test_define'], done);
  10. });
  11. after(function(done) {
  12. Support.Teardown('test_define', done);
  13. });
  14. // Attributes for the test table
  15. var definition = {
  16. id: {
  17. columnType: 'serial',
  18. autoIncrement: true
  19. },
  20. name: {
  21. columnType: 'text',
  22. notNull: true
  23. },
  24. email: {
  25. columnType: 'text'
  26. },
  27. title: {
  28. columnType: 'text'
  29. },
  30. phone: {
  31. columnType: 'text'
  32. },
  33. type: {
  34. columnType: 'text'
  35. },
  36. favoriteFruit: {
  37. columnType: 'text'
  38. },
  39. age: {
  40. columnType: 'integer'
  41. }
  42. };
  43. it('should create a table in the database', function(done) {
  44. Adapter.define('test', 'test_define', definition, function(err) {
  45. if (err) {
  46. return done(err);
  47. }
  48. Adapter.describe('test', 'test_define', function(err, result) {
  49. if (err) {
  50. return done(err);
  51. }
  52. assert(_.isPlainObject(result));
  53. assert.equal(_.keys(result).length, 8);
  54. assert(result.id);
  55. assert(result.name);
  56. assert(result.email);
  57. assert(result.title);
  58. assert(result.phone);
  59. assert(result.type);
  60. assert(result.favoriteFruit);
  61. assert(result.age);
  62. return done();
  63. });
  64. });
  65. });
  66. });
  67. });