mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	more tests
This commit is contained in:
		
							parent
							
								
									c93dad37be
								
							
						
					
					
						commit
						cfdcf4e2e4
					
				| @ -37,10 +37,18 @@ test('diffs a feature-update event', t => { | |||||||
| 
 | 
 | ||||||
|     eventDiffer.addDiffs(events); |     eventDiffer.addDiffs(events); | ||||||
| 
 | 
 | ||||||
|     t.deepEqual(events[0].diffs, [ |     const diffs = events[0].diffs; | ||||||
|         { kind: 'E', path: ['enabled'], lhs: false, rhs: true }, |     t.true(diffs[0].kind === 'E'); | ||||||
|         { kind: 'E', path: ['parameters', 'value'], lhs: 1, rhs: 2 }, |     t.true(diffs[0].path[0] === 'enabled'); | ||||||
|     ]); |     t.true(diffs[0].kind === 'E'); | ||||||
|  |     t.true(diffs[0].lhs === false); | ||||||
|  |     t.true(diffs[0].rhs); | ||||||
|  | 
 | ||||||
|  |     t.true(diffs[1].kind === 'E'); | ||||||
|  |     t.true(diffs[1].path[0] === 'parameters'); | ||||||
|  |     t.true(diffs[1].path[1] === 'value'); | ||||||
|  |     t.true(diffs[1].kind === 'E'); | ||||||
|  |     t.true(diffs[1].lhs === 1); | ||||||
| 
 | 
 | ||||||
|     t.true(events[1].diffs === null); |     t.true(events[1].diffs === null); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| const DEFAULT_OPTIONS = { | const DEFAULT_OPTIONS = { | ||||||
|     databaseUri: process.env.DATABASE_URL || 'postgres://unleash_user:passord@localhost:5432/unleash', |     databaseUri: process.env.DATABASE_URL, | ||||||
|     port: process.env.HTTP_PORT || process.env.PORT || 4242, |     port: process.env.HTTP_PORT || process.env.PORT || 4242, | ||||||
|     baseUriPath: process.env.BASE_URI_PATH || '', |     baseUriPath: process.env.BASE_URI_PATH || '', | ||||||
|     serverMetrics: true, |     serverMetrics: true, | ||||||
| @ -10,7 +10,13 @@ const DEFAULT_OPTIONS = { | |||||||
| module.exports = { | module.exports = { | ||||||
|     createOptions: (opts) => { |     createOptions: (opts) => { | ||||||
|         const options =  Object.assign({}, DEFAULT_OPTIONS, opts); |         const options =  Object.assign({}, DEFAULT_OPTIONS, opts); | ||||||
|          if (!options.databaseUri) { | 
 | ||||||
|  |         // If we are running in development we should assume local db
 | ||||||
|  |         if(process.env.NODE_ENV === 'development' && !options.databaseUri) { | ||||||
|  |             options.databaseUri = 'postgres://unleash_user:passord@localhost:5432/unleash'; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (!options.databaseUri) { | ||||||
|             throw new Error('You must either pass databaseUri option or set environemnt variable DATABASE_URL'); |             throw new Error('You must either pass databaseUri option or set environemnt variable DATABASE_URL'); | ||||||
|         } |         } | ||||||
|         return options; |         return options; | ||||||
|  | |||||||
							
								
								
									
										32
									
								
								lib/options.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								lib/options.test.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | const test = require('ava'); | ||||||
|  | 
 | ||||||
|  | delete process.env.DATABASE_URL; | ||||||
|  | const { createOptions } = require('./options'); | ||||||
|  | 
 | ||||||
|  | test('should require DATABASE_URI', t => { | ||||||
|  |     t.throws(() => { | ||||||
|  |         const options = createOptions({}); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test('should set default databaseUri for develpment', t => { | ||||||
|  |     process.env.NODE_ENV = 'development';     | ||||||
|  |     const { createOptions } = require('./options'); | ||||||
|  |      | ||||||
|  |     const options = createOptions({}); | ||||||
|  | 
 | ||||||
|  |     t.true(options.databaseUri === 'postgres://unleash_user:passord@localhost:5432/unleash'); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test('should not override provided options', t => { | ||||||
|  |     process.env.DATABASE_URL = 'test';     | ||||||
|  |     process.env.NODE_ENV = 'production'; | ||||||
|  | 
 | ||||||
|  |     const { createOptions } = require('./options'); | ||||||
|  |     const options = createOptions({databaseUri: 'test', port: 1111}); | ||||||
|  | 
 | ||||||
|  |     t.true(options.databaseUri === 'test'); | ||||||
|  |     t.true(options.port === 1111); | ||||||
|  | }); | ||||||
| @ -39,7 +39,7 @@ | |||||||
|     "start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev", |     "start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev", | ||||||
|     "db-migrate": "db-migrate up", |     "db-migrate": "db-migrate up", | ||||||
|     "db-migrate:down": "db-migrate down", |     "db-migrate:down": "db-migrate down", | ||||||
|     "test": "PORT=4243 ava test lib/*/*.test.js", |     "test": "PORT=4243 ava test lib/*.test.js lib/**/*.test.js", | ||||||
|     "test:docker": "./scripts/docker-postgres.sh", |     "test:docker": "./scripts/docker-postgres.sh", | ||||||
|     "test:watch": "npm run test -- --watch", |     "test:watch": "npm run test -- --watch", | ||||||
|     "test:pg-virtualenv": "pg_virtualenv npm run test:pg-virtualenv-chai", |     "test:pg-virtualenv": "pg_virtualenv npm run test:pg-virtualenv-chai", | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user