| 
									
										
										
										
											2015-01-03 20:07:09 -05:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2017-02-17 21:55:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-03 20:07:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-15 10:16:58 +03:00
										 |  |  | var	assert = require('assert'); | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | var nconf = require('nconf'); | 
					
						
							| 
									
										
										
										
											2016-10-15 10:16:58 +03:00
										 |  |  | var db = require('./mocks/databasemock'); | 
					
						
							| 
									
										
										
										
											2013-10-30 01:47:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | describe('Test database', () => { | 
					
						
							|  |  |  | 	it('should work', () => { | 
					
						
							|  |  |  | 		assert.doesNotThrow(() => { | 
					
						
							| 
									
										
										
										
											2016-10-15 10:16:58 +03:00
										 |  |  | 			require('./mocks/databasemock'); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('info', () => { | 
					
						
							|  |  |  | 		it('should return info about database', (done) => { | 
					
						
							|  |  |  | 			db.info(db.client, (err, info) => { | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(info); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should not error and return info if client is falsy', (done) => { | 
					
						
							|  |  |  | 			db.info(null, (err, info) => { | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2018-12-10 15:30:10 -05:00
										 |  |  | 				assert(info); | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('checkCompatibility', () => { | 
					
						
							|  |  |  | 		it('should not throw', (done) => { | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 			db.checkCompatibility(done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return error with a too low version', (done) => { | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 			var dbName = nconf.get('database'); | 
					
						
							|  |  |  | 			if (dbName === 'redis') { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.checkCompatibilityVersion('2.4.0', (err) => { | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 					assert.equal(err.message, 'Your Redis version is not new enough to support NodeBB, please upgrade Redis to v2.8.9 or higher.'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else if (dbName === 'mongo') { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.checkCompatibilityVersion('1.8.0', (err) => { | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 					assert.equal(err.message, 'The `mongodb` package is out-of-date, please run `./nodebb setup` again.'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-08-08 14:13:48 -05:00
										 |  |  | 			} else if (dbName === 'postgres') { | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.checkCompatibilityVersion('6.3.0', (err) => { | 
					
						
							| 
									
										
										
										
											2018-08-08 14:13:48 -05:00
										 |  |  | 					assert.equal(err.message, 'The `pg` package is out-of-date, please run `./nodebb setup` again.'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-10-30 01:47:27 +02:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-12-06 13:46:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-19 20:24:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-25 02:43:11 -05:00
										 |  |  | 	require('./database/keys'); | 
					
						
							| 
									
										
										
										
											2014-12-29 16:20:35 -05:00
										 |  |  | 	require('./database/list'); | 
					
						
							| 
									
										
										
										
											2014-12-29 17:55:30 -05:00
										 |  |  | 	require('./database/sets'); | 
					
						
							| 
									
										
										
										
											2014-12-30 18:07:06 -05:00
										 |  |  | 	require('./database/hash'); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 	require('./database/sorted'); | 
					
						
							| 
									
										
										
										
											2013-10-30 01:47:27 +02:00
										 |  |  | }); |