|
| 1 | +function getTests() { |
| 2 | + return [ |
| 3 | + { |
| 4 | + desc: '# get something that does not exist', |
| 5 | + run: function (env, test) { |
| 6 | + env.mod.get('blahblah', function (err, data) { |
| 7 | + test.assertTypeAnd(data, 'undefined'); |
| 8 | + test.assert(err, 'record not found'); |
| 9 | + }); |
| 10 | + } |
| 11 | + }, |
| 12 | + |
| 13 | + { |
| 14 | + desc: '# save string', |
| 15 | + run: function (env, test) { |
| 16 | + env.mod.save('foo', 'hallo', function (err, data) { |
| 17 | + test.assert(err, null); |
| 18 | + }); |
| 19 | + } |
| 20 | + }, |
| 21 | + |
| 22 | + { |
| 23 | + desc: '# get string', |
| 24 | + run: function (env, test) { |
| 25 | + env.mod.get('foo', function (err, data) { |
| 26 | + test.assertAnd(err, null); |
| 27 | + test.assertTypeAnd(data, 'string'); |
| 28 | + test.assert(data, 'hallo'); |
| 29 | + }); |
| 30 | + } |
| 31 | + }, |
| 32 | + |
| 33 | + { |
| 34 | + desc: '# save object', |
| 35 | + run: function (env, test) { |
| 36 | + env.mod.save('foo', { bar: 'baz', wang: 'bang' }, function (err, data) { |
| 37 | + test.assert(err, null); |
| 38 | + }); |
| 39 | + } |
| 40 | + }, |
| 41 | + |
| 42 | + { |
| 43 | + desc: '# get object', |
| 44 | + run: function (env, test) { |
| 45 | + env.mod.get('foo', function (err, data) { |
| 46 | + test.assertAnd(err, null); |
| 47 | + test.assertTypeAnd(data, 'object'); |
| 48 | + test.assert(data, { bar: 'baz', wang: 'bang' }); |
| 49 | + }); |
| 50 | + } |
| 51 | + }, |
| 52 | + |
| 53 | + { |
| 54 | + desc: '# new scope', |
| 55 | + run: function (env, test) { |
| 56 | + env.mod2 = new env.Mod({ |
| 57 | + namespace: 'secure-store-redis-tests', |
| 58 | + secret: 'i dont know the key :(', |
| 59 | + redis: { |
| 60 | + host: '127.0.0.1', |
| 61 | + port: 6379 |
| 62 | + } |
| 63 | + }); |
| 64 | + test.assertTypeAnd(env.mod2, 'object'); |
| 65 | + test.assertTypeAnd(env.mod2.get, 'function'); |
| 66 | + test.assertType(env.mod2.save, 'function'); |
| 67 | + } |
| 68 | + }, |
| 69 | + |
| 70 | + |
| 71 | + { |
| 72 | + desc: '# get (wrong secret)', |
| 73 | + run: function (env, test) { |
| 74 | + env.mod2.get('foo', function (err, data) { |
| 75 | + test.assertAnd(err, 'unable to decrypt'); |
| 76 | + test.assertType(data, 'undefined'); |
| 77 | + }); |
| 78 | + } |
| 79 | + }, |
| 80 | + |
| 81 | + { |
| 82 | + desc: '# save complex object', |
| 83 | + run: function (env, test) { |
| 84 | + env.complexObj = { |
| 85 | + foo: 'bar', |
| 86 | + bad: 'obj', |
| 87 | + this: true, |
| 88 | + me: { |
| 89 | + o: { |
| 90 | + me: { |
| 91 | + o: [true, false, true, null, 'this', 'that', true, 9] |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + }; |
| 96 | + env.mod2.save('complex', env.complexObj, function (err) { |
| 97 | + test.assert(err, null); |
| 98 | + }); |
| 99 | + } |
| 100 | + }, |
| 101 | + |
| 102 | + { |
| 103 | + desc: '# get complex object', |
| 104 | + run: function (env, test) { |
| 105 | + env.mod2.get('complex', function (err, data) { |
| 106 | + test.assertAnd(err, null); |
| 107 | + test.assertTypeAnd(data, 'object'); |
| 108 | + test.assert(data, env.complexObj); |
| 109 | + }); |
| 110 | + } |
| 111 | + }, |
| 112 | + |
| 113 | + ]; |
| 114 | +} |
| 115 | + |
| 116 | +if (typeof define !== 'function') { |
| 117 | + var define = require('amdefine')(module); |
| 118 | +} |
| 119 | +define(['require'], function (require) { |
| 120 | + return [{ |
| 121 | + desc: "basic tests", |
| 122 | + abortOnFail: true, |
| 123 | + setup: function (env, test) { |
| 124 | + env.Mod = require('./../index'); |
| 125 | + test.assertTypeAnd(env.Mod, 'function'); |
| 126 | + env.mod = new env.Mod({ |
| 127 | + namespace: 'secure-store-redis-tests', |
| 128 | + secret: 'sssh dont say nuthin!', |
| 129 | + redis: { |
| 130 | + host: '127.0.0.1', |
| 131 | + port: 6379 |
| 132 | + } |
| 133 | + }); |
| 134 | + test.assertTypeAnd(env.mod, 'object'); |
| 135 | + test.assertTypeAnd(env.mod.get, 'function'); |
| 136 | + test.assertType(env.mod.save, 'function'); |
| 137 | + }, |
| 138 | + tests: getTests(), |
| 139 | + }]; |
| 140 | +}); |
0 commit comments