Showing
4 changed files
with
27 additions
and
10 deletions
@@ -26,12 +26,10 @@ camelCaseArray = (list) => { | @@ -26,12 +26,10 @@ camelCaseArray = (list) => { | ||
26 | }; | 26 | }; |
27 | 27 | ||
28 | camelCase = (data) => { | 28 | camelCase = (data) => { |
29 | - if (_.isObject(data)) { | ||
30 | - data = camelCaseObject(data); | ||
31 | - } | ||
32 | - | ||
33 | if (_.isArray(data)) { | 29 | if (_.isArray(data)) { |
34 | data = camelCaseArray(data); | 30 | data = camelCaseArray(data); |
31 | + } else if (_.isObject(data)) { | ||
32 | + data = camelCaseObject(data); | ||
35 | } | 33 | } |
36 | 34 | ||
37 | return data; | 35 | return data; |
@@ -30,7 +30,21 @@ test('api get test', t => { | @@ -30,7 +30,21 @@ test('api get test', t => { | ||
30 | let api = new ServiceAPI(); | 30 | let api = new ServiceAPI(); |
31 | 31 | ||
32 | return api.get(getUrl, sign.apiSign({})).then(result => { | 32 | return api.get(getUrl, sign.apiSign({})).then(result => { |
33 | - if (result && (result.code === 200 || result.code === 500)) { | 33 | + if (result && result.code) { |
34 | + t.pass(); | ||
35 | + } else { | ||
36 | + t.fail(); | ||
37 | + } | ||
38 | + }); | ||
39 | +}); | ||
40 | + | ||
41 | +test('api get test, api return an error', t => { | ||
42 | + let api = new ServiceAPI(); | ||
43 | + | ||
44 | + return api.get(getUrl + '/error', sign.apiSign({})).catch(err => { | ||
45 | + | ||
46 | + // 故意调用一个错误的接口 | ||
47 | + if (err && err.code === 500) { | ||
34 | t.pass(); | 48 | t.pass(); |
35 | } else { | 49 | } else { |
36 | t.fail(); | 50 | t.fail(); |
@@ -42,7 +56,7 @@ test('api get use cache test', t => { | @@ -42,7 +56,7 @@ test('api get use cache test', t => { | ||
42 | let api = new ServiceAPI(); | 56 | let api = new ServiceAPI(); |
43 | 57 | ||
44 | return api.get(getUrl, sign.apiSign({}), true).then(result => { | 58 | return api.get(getUrl, sign.apiSign({}), true).then(result => { |
45 | - if (result && (result.code === 200 || result.code === 500)) { | 59 | + if (result && result.code) { |
46 | t.pass(); | 60 | t.pass(); |
47 | } else { | 61 | } else { |
48 | t.fail(); | 62 | t.fail(); |
@@ -54,7 +68,7 @@ test('api post test', t => { | @@ -54,7 +68,7 @@ test('api post test', t => { | ||
54 | let api = new ServiceAPI(); | 68 | let api = new ServiceAPI(); |
55 | 69 | ||
56 | return api.post(getUrl, sign.apiSign({})).then(result => { | 70 | return api.post(getUrl, sign.apiSign({})).then(result => { |
57 | - if (result && (result.code === 200 || result.code === 500)) { | 71 | + if (result && result.code) { |
58 | t.pass(); | 72 | t.pass(); |
59 | } else { | 73 | } else { |
60 | t.fail(); | 74 | t.fail(); |
@@ -60,10 +60,13 @@ test('cache get multi from slave test', (t) => { | @@ -60,10 +60,13 @@ test('cache get multi from slave test', (t) => { | ||
60 | }); | 60 | }); |
61 | 61 | ||
62 | test('cache set to slave', (t) => { | 62 | test('cache set to slave', (t) => { |
63 | - return cache.setSlave(slaveTestKey, slaveTestValue).then(() => { | 63 | + return cache.setSlave(slaveTestKey, { |
64 | + value: slaveTestValue | ||
65 | + }).then(() => { | ||
64 | return cache.getFromSlave(slaveTestKey); | 66 | return cache.getFromSlave(slaveTestKey); |
65 | }).then((v) => { | 67 | }).then((v) => { |
66 | - t.is(v, slaveTestValue); | 68 | + v = JSON.parse(v); |
69 | + t.is(v.value, slaveTestValue); | ||
67 | cache.del(slaveTestKey); | 70 | cache.del(slaveTestKey); |
68 | }); | 71 | }); |
69 | }); | 72 | }); |
@@ -20,7 +20,9 @@ test('camel case object', t => { | @@ -20,7 +20,9 @@ test('camel case object', t => { | ||
20 | test('camel case array', t => { | 20 | test('camel case array', t => { |
21 | let arr = [{ | 21 | let arr = [{ |
22 | A_B: 'ab_cd' | 22 | A_B: 'ab_cd' |
23 | + }, { | ||
24 | + A_B: 'ab_cd' | ||
23 | }]; | 25 | }]; |
24 | 26 | ||
25 | - t.is(camelCase(arr)[0].aB, 'ab_cd'); | 27 | + t.is(camelCase(arr)[1].aB, 'ab_cd'); |
26 | }); | 28 | }); |
-
Please register or login to post a comment