mythix 1.2.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/package.json +6 -13
  2. package/src/application.js +5 -2
  3. package/src/cli/migrations/makemigrations-command.js +1 -2
  4. package/src/cli/migrations/migrate-command.js +4 -4
  5. package/src/cli/shell-command.js +0 -2
  6. package/src/controllers/controller-module.js +0 -9
  7. package/src/http-server/http-server.js +0 -5
  8. package/src/models/index.js +0 -4
  9. package/src/models/migration-model.js +2 -2
  10. package/src/models/model-module.js +19 -32
  11. package/src/models/model-utils.js +24 -374
  12. package/src/models/model.js +29 -150
  13. package/src/modules/database-module.js +23 -18
  14. package/src/tasks/task-module.js +1 -11
  15. package/src/tasks/task-utils.js +1 -2
  16. package/src/utils/test-utils.js +38 -50
  17. package/.eslintrc.js +0 -94
  18. package/.vscode/settings.json +0 -7
  19. package/spec/controllers/controller-utils-spec.js +0 -145
  20. package/spec/controllers/generate-client-api-interface-spec.js +0 -156
  21. package/spec/controllers/generateClientAPIInterface01.snapshot +0 -552
  22. package/spec/controllers/generateClientAPIInterface02.snapshot +0 -465
  23. package/spec/controllers/generateClientAPIInterface03.snapshot +0 -418
  24. package/spec/controllers/generateClientAPIInterface04.snapshot +0 -552
  25. package/spec/controllers/generateClientAPIInterface05.snapshot +0 -552
  26. package/spec/support/application.js +0 -50
  27. package/spec/support/config/index.js +0 -3
  28. package/spec/support/jasmine.json +0 -13
  29. package/spec/support/snapshots.js +0 -63
  30. package/spec/utils/crypto-utils-spec.js +0 -28
  31. package/spec/utils/file-utils-spec.js +0 -14
  32. package/spec/utils/mime-utils-spec.js +0 -175
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const Nife = require('nife');
4
- const { Sequelize } = require('sequelize');
5
4
  const { BaseModule } = require('../modules/base-module');
6
5
  const {
7
6
  fileNameWithoutExtension,
@@ -85,7 +84,7 @@ class TaskModule extends BaseModule {
85
84
  let connection = (typeof application.getDBConnection === 'function') ? application.getDBConnection() : null;
86
85
  let dbConfig = (typeof application.getDBConfig === 'function') ? application.getDBConfig() : null;
87
86
  let tasks = {};
88
- let args = { application: this, Sequelize, connection, dbConfig };
87
+ let args = { application: this, connection, dbConfig };
89
88
 
90
89
  for (let i = 0, il = taskFiles.length; i < il; i++) {
91
90
  let taskFile = taskFiles[i];
@@ -102,15 +101,6 @@ class TaskModule extends BaseModule {
102
101
  }
103
102
  }
104
103
 
105
- Object.defineProperties(tasks, {
106
- '_files': {
107
- writable: true,
108
- enumberable: false,
109
- configurable: true,
110
- value: taskFiles,
111
- },
112
- });
113
-
114
104
  return tasks;
115
105
  }
116
106
 
@@ -83,13 +83,12 @@ class TimeHelpers {
83
83
  function defineTask(taskName, definer, _parent) {
84
84
  let parentKlass = _parent || TaskBase;
85
85
 
86
- return function({ application, Sequelize, connection, dbConfig }) {
86
+ return function({ application, connection, dbConfig }) {
87
87
  let time = new TimeHelpers();
88
88
 
89
89
  let Klass = definer({
90
90
  Parent: parentKlass,
91
91
  application,
92
- Sequelize,
93
92
  connection,
94
93
  dbConfig,
95
94
  taskName,
@@ -3,21 +3,16 @@
3
3
  /* global process */
4
4
 
5
5
  const Nife = require('nife');
6
+ const { Utils } = require('mythix-orm');
6
7
  const { Logger } = require('../logger');
7
- const HTTPUtils = require('./http-utils');
8
8
  const { HTTPInterface } = require('./http-interface');
9
9
  const { DatabaseModule } = require('../modules/database-module');
10
10
  const { HTTPServerModule } = require('../http-server/http-server-module');
11
11
 
12
12
  class TestDatabaseModule extends DatabaseModule {
13
- getDatabaseConfig() {
14
- let config = super.getDatabaseConfig();
15
- return Object.assign({}, config, { dialect: 'sqlite', storage: ':memory:' });
16
- }
17
-
18
13
  getTablePrefix() {
19
14
  let prefix = super.getTablePrefix();
20
- return `${prefix.replace(/_test/g, '')}_test_`.replace(/_+/g, '_');
15
+ return `${prefix.replace(/_test/g, '')}_test_`.replace(/_+/g, '_').replace(/\W+/g, '_');
21
16
  }
22
17
  }
23
18
 
@@ -69,9 +64,10 @@ function createTestApplication(Application) {
69
64
 
70
65
  constructor(_opts) {
71
66
  let opts = Nife.extend(true, {
72
- autoReload: false,
73
- runTasks: false,
74
- testMode: true,
67
+ environment: 'test',
68
+ autoReload: false,
69
+ runTasks: false,
70
+ testMode: true,
75
71
  }, _opts || {});
76
72
 
77
73
  super(opts);
@@ -103,33 +99,53 @@ function createTestApplication(Application) {
103
99
  let result = await super.start(...args);
104
100
 
105
101
  if (typeof this.getDBConnection === 'function') {
106
- let dbConnection = this.getDBConnection();
107
- await dbConnection.sync({ force: true, logging: false });
102
+ let connection = this.getDBConnection();
103
+ await this.createAllTables(connection);
108
104
  }
109
105
 
110
106
  return result;
111
107
  }
112
108
 
109
+ async createAllTables(connection) {
110
+ const createTable = async (connection, Model, options) => {
111
+ return await connection.createTable(Model, options);
112
+ };
113
+
114
+ let models = connection.getModels();
115
+ let modelNames = Object.keys(models);
116
+
117
+ modelNames = Utils.sortModelNamesByCreationOrder(connection, modelNames);
118
+
119
+ for (let i = 0, il = modelNames.length; i < il; i++) {
120
+ let modelName = modelNames[i];
121
+ let model = models[modelName];
122
+
123
+ await createTable(connection, model, { ifNotExists: true });
124
+ }
125
+ }
126
+
113
127
  async truncateAllTables(exclude) {
114
- let dbConnection = this.getDBConnection();
115
- let models = this.getModels();
116
- let modelNames = Object.keys(models);
128
+ let connection = this.getDBConnection();
129
+ let models = this.getModels();
130
+ let modelNames = Object.keys(models);
117
131
 
118
- await dbConnection.query('PRAGMA foreign_keys = OFF');
132
+ modelNames = Utils.sortModelNamesByCreationOrder(connection, modelNames);
133
+
134
+ await connection.enableForeignKeyConstraints(false);
119
135
 
120
136
  try {
121
- for (let i = 0, il = modelNames.length; i < il; i++) {
137
+ for (let i = modelNames.length - 1; i >= 0; i--) {
122
138
  let modelName = modelNames[i];
123
139
  if (exclude && exclude.indexOf(modelName) >= 0)
124
140
  continue;
125
141
 
126
- let model = models[modelName];
127
- await dbConnection.query(`DELETE FROM "${model.tableName}"`);
142
+ let Model = models[modelName];
143
+ await connection.truncate(Model);
128
144
  }
129
145
  } catch (error) {
130
146
  console.error('TRUNCATE ERROR: ', error);
131
147
  } finally {
132
- await dbConnection.query('PRAGMA foreign_keys = ON');
148
+ await connection.enableForeignKeyConstraints(true);
133
149
  }
134
150
  }
135
151
 
@@ -140,36 +156,8 @@ function createTestApplication(Application) {
140
156
  try {
141
157
  let Klass = callback.call(this, OriginalModel);
142
158
 
143
- const modelConverter = (model) => {
144
- if (model == null)
145
- return model;
146
-
147
- if (model instanceof Array)
148
- return model.map(modelConverter);
149
-
150
- // Do a direct assign to "dataValues"
151
- // "set" modifies the id
152
- let newModelInstance = new Klass();
153
- Object.assign(newModelInstance.dataValues, model.dataValues);
154
-
155
- return newModelInstance;
156
- };
157
-
158
- const modelStaticBind = (name) => {
159
- const originalMethod = Klass[name];
160
-
161
- return (async function(...args) {
162
- let results = await originalMethod.call(Klass, ...args);
163
- return modelConverter(results);
164
- }).bind(Klass);
165
- };
166
-
167
- Klass.where = modelStaticBind('where');
168
- Klass.all = modelStaticBind('all');
169
- Klass.first = modelStaticBind('first');
170
- Klass.last = modelStaticBind('last');
171
-
172
- models[modelName] = Klass;
159
+ let connection = this.getDBConnection();
160
+ connection.registerModel(Klass);
173
161
 
174
162
  return await runner.call(this, Klass);
175
163
  } finally {
package/.eslintrc.js DELETED
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- /* eslint-disable no-magic-numbers */
4
-
5
- module.exports = {
6
- 'env': {
7
- 'browser': true,
8
- 'commonjs': true,
9
- 'es2021': true,
10
- },
11
- 'extends': [
12
- 'eslint:recommended',
13
- ],
14
- 'parserOptions': {
15
- 'ecmaVersion': 'latest',
16
- },
17
- 'plugins': [
18
- '@spothero/eslint-plugin-spothero',
19
- ],
20
- 'rules': {
21
- '@spothero/spothero/ternary-parentheses': 'error',
22
- 'arrow-parens': 'error',
23
- 'arrow-spacing': [ 'error', { before: true, after: true } ],
24
- 'block-scoped-var': 'warn',
25
- 'block-spacing': 'error',
26
- 'brace-style': [ 'error', '1tbs' ],
27
- 'camelcase': 'warn',
28
- 'comma-dangle': [ 'error', 'always-multiline' ],
29
- 'comma-spacing': [ 'error', { before: false, after: true } ],
30
- 'comma-style': [ 'error', 'last' ],
31
- 'curly': [ 'error', 'multi-or-nest', 'consistent' ],
32
- 'default-case-last': 'error',
33
- 'default-param-last': 'error',
34
- 'eqeqeq': [ 'error', 'smart' ],
35
- 'func-call-spacing': [ 'error', 'never' ],
36
- 'guard-for-in': 'error',
37
- 'implicit-arrow-linebreak': [ 'error', 'beside' ],
38
- 'indent': [ 'error', 2, { 'SwitchCase': 1 } ],
39
- 'jsx-quotes': [ 'error', 'prefer-double' ],
40
- 'key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'minimum', 'align': 'value' } ],
41
- 'keyword-spacing': [ 'error', { before: true, after: true } ],
42
- 'linebreak-style': [ 'error', 'unix' ],
43
- 'lines-between-class-members': 'error',
44
- 'max-classes-per-file': [ 'error', 3 ],
45
- 'new-cap': [ 'error', { 'properties': false } ],
46
- 'new-parens': 'error',
47
- 'no-array-constructor': 'warn',
48
- 'no-caller': 'error',
49
- 'no-confusing-arrow': 'error',
50
- 'no-empty': 'warn',
51
- 'no-eq-null': 0,
52
- 'no-eval': 'error',
53
- 'no-extend-native': 'error',
54
- 'no-extra-label': 'error',
55
- 'no-floating-decimal': 'error',
56
- 'no-global-assign': 'error',
57
- 'no-implied-eval': 'error',
58
- 'no-labels': 'error',
59
- 'no-lone-blocks': 'warn',
60
- 'no-loop-func': 0,
61
- 'no-magic-numbers': [ 'warn', { ignoreArrayIndexes: true, ignoreDefaultValues: true, ignore: [ -1, 0, 1, 2, 16, 32, 64, 128, 256, 1024, 2048, 200, 301, 302, 400, 401, 403, 404, 500 ] } ],
62
- 'no-nested-ternary': 'error',
63
- 'no-param-reassign': 'error',
64
- 'no-promise-executor-return': 'error',
65
- 'no-return-assign': 'error',
66
- 'no-sequences': 'error',
67
- 'no-shadow': 0,
68
- 'no-throw-literal': 'warn',
69
- 'no-trailing-spaces': 'error',
70
- 'no-unmodified-loop-condition': 'warn',
71
- 'no-unreachable-loop': 'warn',
72
- 'no-unreachable': 'warn',
73
- 'no-unused-private-class-members': 'warn',
74
- 'no-unused-vars': 'warn',
75
- 'no-whitespace-before-property': 'error',
76
- 'nonblock-statement-body-position': [ 'error', 'below' ],
77
- 'one-var': [ 'error', 'never' ],
78
- 'quotes': [ 'error', 'single' ],
79
- 'radix': 'error',
80
- 'rest-spread-spacing': [ 'error', 'never' ],
81
- 'semi-spacing': [ 'error', { before: false, after: true } ],
82
- 'semi-style': [ 'error', 'last' ],
83
- 'semi': 'error',
84
- 'space-before-blocks': 'error',
85
- 'space-infix-ops': 'error',
86
- 'space-unary-ops': [ 'error', { words: false, nonwords: false } ],
87
- 'strict': 'error',
88
- 'switch-colon-spacing': [ 'error', { before: false, after: true } ],
89
- 'template-curly-spacing': 'error',
90
- 'template-tag-spacing': 'error',
91
- 'wrap-iife': [ 'error', 'inside' ],
92
- 'yoda': 'error',
93
- },
94
- };
@@ -1,7 +0,0 @@
1
- {
2
- "workbench.colorCustomizations": {
3
- "activityBar.background": "#5F0A17",
4
- "titleBar.activeBackground": "#840E20",
5
- "titleBar.activeForeground": "#FFFBFC"
6
- }
7
- }
@@ -1,145 +0,0 @@
1
- 'use strict';
2
-
3
- /* global describe, it, expect */
4
-
5
- const ControllerUtils = require('../../src/controllers/controller-utils');
6
-
7
- describe('controller-utils', function() {
8
- describe('buildMethodMatcher', function() {
9
- it('should be able to create a method matcher', function() {
10
- let matchFunc = ControllerUtils.buildMethodMatcher('*');
11
- expect(matchFunc(null)).toBe(true);
12
- expect(matchFunc('')).toBe(true);
13
- expect(matchFunc('GET')).toBe(true);
14
- expect(matchFunc('get')).toBe(true);
15
- expect(matchFunc('Post')).toBe(true);
16
-
17
- matchFunc = ControllerUtils.buildMethodMatcher([ 'GET', '*' ]);
18
- expect(matchFunc('')).toBe(true);
19
- expect(matchFunc('GET')).toBe(true);
20
- expect(matchFunc('get')).toBe(true);
21
- expect(matchFunc('Post')).toBe(true);
22
-
23
- matchFunc = ControllerUtils.buildMethodMatcher('GET');
24
- expect(matchFunc('GET')).toBe(true);
25
- expect(matchFunc('get')).toBe(true);
26
- expect(matchFunc('GETs')).toBe(false);
27
- expect(matchFunc('post')).toBe(false);
28
-
29
- matchFunc = ControllerUtils.buildMethodMatcher([ 'get', 'POST' ]);
30
- expect(matchFunc('GET')).toBe(true);
31
- expect(matchFunc('get')).toBe(true);
32
- expect(matchFunc('POST')).toBe(true);
33
- expect(matchFunc('head')).toBe(false);
34
-
35
- matchFunc = ControllerUtils.buildMethodMatcher(/(get|post)/i);
36
- expect(matchFunc('GET')).toBe(true);
37
- expect(matchFunc('get')).toBe(true);
38
- expect(matchFunc('gets')).toBe(true);
39
- expect(matchFunc('POST')).toBe(true);
40
- expect(matchFunc('POSTs')).toBe(true);
41
- expect(matchFunc('head')).toBe(false);
42
- });
43
- });
44
-
45
- describe('buildContentTypeMatcher', function() {
46
- it('should be able to create a content-type matcher', function() {
47
- let matcher = ControllerUtils.buildContentTypeMatcher('*');
48
- expect(matcher.regexp.toString()).toBe('/.*/i');
49
- expect(matcher('application/json')).toBe(true);
50
- expect(matcher('anything')).toBe(true);
51
- expect(matcher()).toBe(true);
52
-
53
- matcher = ControllerUtils.buildContentTypeMatcher('application/json');
54
- expect(matcher.regexp.toString()).toBe('/(application\\/json)/i');
55
- expect(matcher('application/json')).toBe(true);
56
- expect(matcher('application/json; charset=UTF-8')).toBe(true);
57
- expect(matcher('text/plain')).toBe(false);
58
-
59
- matcher = ControllerUtils.buildContentTypeMatcher(/^(application\/json|text\/plain)$/i);
60
- expect(matcher.regexp.toString()).toBe('/^(application\\/json|text\\/plain)$/i');
61
- expect(matcher('application/json')).toBe(true);
62
- expect(matcher('application/json; charset=UTF-8')).toBe(false);
63
- expect(matcher('text/plain')).toBe(true);
64
- expect(matcher('text/plain;')).toBe(false);
65
- });
66
- });
67
-
68
- describe('buildPathMatcher', function() {
69
- it('should be able to build a parser from a route name', function() {
70
- let matchFunc = ControllerUtils.buildPathMatcher('person<id?:integer = 0>_stuff');
71
- expect(matchFunc('person120_stuff')).toEqual({ id: 120 });
72
- expect(matchFunc('person_stuff')).toEqual({});
73
-
74
- matchFunc = ControllerUtils.buildPathMatcher('objects/<id>');
75
- expect(matchFunc('objects')).toBe(undefined);
76
- expect(matchFunc('objects/')).toBe(undefined);
77
- expect(matchFunc('objects/1')).toEqual({ id: 1 });
78
-
79
- matchFunc = ControllerUtils.buildPathMatcher('objects/<id?>');
80
- expect(matchFunc('objects')).toEqual({});
81
- expect(matchFunc('objects/')).toEqual({});
82
- expect(matchFunc('objects/1')).toEqual({ id: 1 });
83
-
84
- matchFunc = ControllerUtils.buildPathMatcher('values/<truthy:boolean>');
85
- expect(matchFunc('values')).toBe(undefined);
86
- expect(matchFunc('values/')).toBe(undefined);
87
- expect(matchFunc('values/1')).toBe(undefined);
88
- expect(matchFunc('values/derp')).toBe(undefined);
89
- expect(matchFunc('values/true')).toEqual({ truthy: true });
90
- expect(matchFunc('values/True')).toEqual({ truthy: true });
91
- expect(matchFunc('values/TRUE')).toEqual({ truthy: true });
92
- expect(matchFunc('values/false')).toEqual({ truthy: false });
93
- expect(matchFunc('values/False')).toEqual({ truthy: false });
94
- expect(matchFunc('values/FALSE')).toEqual({ truthy: false });
95
-
96
- matchFunc = ControllerUtils.buildPathMatcher('values/<str:magic>', { magic: (part) => `MAGIC:${part}!!!`});
97
- expect(matchFunc('values')).toBe(undefined);
98
- expect(matchFunc('values/')).toBe(undefined);
99
- expect(matchFunc('values/1')).toEqual({ str: 'MAGIC:1!!!' });
100
- expect(matchFunc('values/derp')).toEqual({ str: 'MAGIC:derp!!!' });
101
- });
102
- });
103
-
104
- describe('buildRoutes', function() {
105
- it('should be able to compile routes', function() {
106
- // let allRoutes = ControllerUtils.buildRoutes({
107
- // 'api': {
108
- // 'v1': {
109
- // 'test': {
110
- // methods: [ 'GET', 'POST' ],
111
- // accept: 'application/json',
112
- // controller: 'Something.test',
113
- // children: [
114
- // {
115
- // priority: 10,
116
- // methods: 'GET',
117
- // controller: 'Something.children.get',
118
- // },
119
- // {
120
- // priority: 11,
121
- // methods: 'POST',
122
- // controller: 'Something.children.post',
123
- // },
124
- // {
125
- // 'do-something/<id:int>': {
126
- // priority: 10,
127
- // methods: 'GET',
128
- // controller: 'Something.children.get.doSomething',
129
- // },
130
- // },
131
- // ],
132
- // },
133
- // 'test2': {
134
- // priority: 0,
135
- // methods: [ 'POST', '*' ],
136
- // controller: 'Something.test2',
137
- // },
138
- // },
139
- // },
140
- // });
141
-
142
- // console.log('ALL ROUTES: ', allRoutes);
143
- });
144
- });
145
- });
@@ -1,156 +0,0 @@
1
- 'use strict';
2
-
3
- /* global describe, it, beforeAll, expect, __dirname */
4
-
5
- const { generateClientAPIInterface } = require('../../src/controllers/generate-client-api-interface');
6
- const { newTestApplication } = require('../support/application');
7
- const { _matchesSnapshot } = require('../support/snapshots');
8
-
9
- const matchesSnapshot = _matchesSnapshot.bind(this, __dirname);
10
-
11
- function getRoutes() {
12
- return {
13
- 'api': {
14
- 'v1': {
15
- 'auth': {
16
- 'authenticate': [
17
- {
18
- 'methods': [ 'GET' ],
19
- 'controller': 'AuthController.authenticate',
20
- },
21
- {
22
- 'name': 'login',
23
- 'methods': [ 'POST' ],
24
- 'accept': [ 'application/json' ],
25
- 'controller': 'AuthController.authenticate',
26
- },
27
- ],
28
- 'sendMagicLink': [
29
- {
30
- 'name': 'sendMagicLink',
31
- 'methods': [ 'POST' ],
32
- 'accept': [ 'application/json' ],
33
- 'controller': 'AuthController.sendMagicLink',
34
- },
35
- ],
36
- 'registerUser': [
37
- {
38
- 'name': 'registerUser',
39
- 'methods': [ 'POST' ],
40
- 'accept': [ 'application/json' ],
41
- 'controller': 'AuthController.registerUser',
42
- },
43
- ],
44
- },
45
- 'user': {
46
- '/<userID:string>': [
47
- {
48
- 'name': 'getUser',
49
- 'methods': [ 'GET' ],
50
- 'accept': [ 'application/json' ],
51
- 'controller': 'UserController.show',
52
- },
53
- {
54
- 'name': 'updateUser',
55
- 'methods': [ 'POST', 'PATCH' ],
56
- 'accept': [ 'application/json' ],
57
- 'controller': 'UserController.update',
58
- },
59
- ],
60
- '/search': {
61
- 'name': 'searchUsers',
62
- 'methods': [ 'POST' ],
63
- 'accept': [ 'application/json' ],
64
- 'controller': 'UserController.list',
65
- },
66
- '/': [
67
- {
68
- 'name': 'getUsers',
69
- 'methods': [ 'GET' ],
70
- 'accept': [ 'application/json' ],
71
- 'controller': 'UserController.list',
72
- },
73
- ],
74
- },
75
- 'organization': {
76
- '/<organizationID:string>': [
77
- {
78
- 'name': 'getOrganization',
79
- 'methods': [ 'GET' ],
80
- 'accept': [ 'application/json' ],
81
- 'controller': 'OrganizationController.show',
82
- },
83
- {
84
- 'name': 'updateOrganization',
85
- 'methods': [ 'POST', 'PATCH' ],
86
- 'accept': [ 'application/json' ],
87
- 'controller': 'OrganizationController.update',
88
- },
89
- ],
90
- '/<organizationID:string>/inviteUser': [
91
- {
92
- 'name': 'inviteUserToOrganization',
93
- 'methods': [ 'POST' ],
94
- 'accept': [ 'application/json' ],
95
- 'controller': 'OrganizationController.inviteUser',
96
- },
97
- ],
98
- '/search': {
99
- 'name': 'searchOrganizations',
100
- 'methods': [ 'POST' ],
101
- 'accept': [ 'application/json' ],
102
- 'controller': 'OrganizationController.list',
103
- },
104
- '/': [
105
- {
106
- 'name': 'getOrganizations',
107
- 'methods': [ 'GET' ],
108
- 'accept': [ 'application/json' ],
109
- 'controller': 'OrganizationController.list',
110
- },
111
- {
112
- 'name': 'createOrganization',
113
- 'methods': [ 'PUT' ],
114
- 'accept': [ 'application/json' ],
115
- 'controller': 'OrganizationController.create',
116
- },
117
- ],
118
- },
119
- },
120
- },
121
- };
122
- }
123
-
124
- describe('generateClientAPIInterface', () => {
125
- let app;
126
-
127
- beforeAll(async () => {
128
- app = await newTestApplication();
129
- app.getRoutes = getRoutes.bind(app);
130
- });
131
-
132
- it('should be able to generate an interface using route definitions', () => {
133
- let result = generateClientAPIInterface(app);
134
- expect(matchesSnapshot('generateClientAPIInterface01', result)).toBe(true);
135
- });
136
-
137
- it('should be able to generate an interface for node', () => {
138
- let result = generateClientAPIInterface(app, { environment: 'node' });
139
- expect(matchesSnapshot('generateClientAPIInterface02', result)).toBe(true);
140
- });
141
-
142
- it('should be able to generate an interface for the browser', () => {
143
- let result = generateClientAPIInterface(app, { environment: 'browser' });
144
- expect(matchesSnapshot('generateClientAPIInterface03', result)).toBe(true);
145
- });
146
-
147
- it('should be able to export a global', () => {
148
- let result = generateClientAPIInterface(app, { globalName: 'API' });
149
- expect(matchesSnapshot('generateClientAPIInterface04', result)).toBe(true);
150
- });
151
-
152
- it('should be able to specify a domain', () => {
153
- let result = generateClientAPIInterface(app, { domain: 'http://localhost:8080' });
154
- expect(matchesSnapshot('generateClientAPIInterface05', result)).toBe(true);
155
- });
156
- });