Skip to content

Commit f4536a5

Browse files
committed
changed few query comands & rename files
1 parent d5d0587 commit f4536a5

9 files changed

+77
-83
lines changed

featured/featured-test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
/* jshint mocha: true */
1+
/* eslint-env mocha */
2+
"use strict";
23
var core = new (require('ebus'))();
34
var assert = require('assert');
45
var config = require('../server-config-defaults.js');
56
require('./featured.js')(core, config.featured);
7+
var redis = require("redis").createClient();
68
describe('Featured tests', function() {
9+
before("before", function(done){
10+
redis.select(config.featured.redisDB);
11+
redis.sadd("featured:room", ["someroom"], done);
712

13+
});
814
it("getRooms API: (get featured rooms)", function(done) {
915
core.emit("getRooms", {featured: true}, function(err, results) {
1016
assert.equal(results.ref instanceof Array, true, "Should update query( ref is not an array)");

storage/storage-test.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
require('./test/contentActions-test.js');
2-
require('./test/contentQueries-test.js');
3-
require('./test/entityActions-test.js');
4-
require('./test/entityQueries-test.js');
5-
require('./test/noteActions-test.js');
6-
require('./test/noteQueries-test.js');
1+
require('./test/content-actions-test.js');
2+
require('./test/content-queries-test.js');
3+
require('./test/entity-actions-test.js');
4+
require('./test/entity-queries-test.js');
5+
require('./test/note-actions-test.js');
6+
require('./test/note-queries-test.js');
7+
require('./test/relation-actions-test.js');

storage/test/contentActions-test.js renamed to storage/test/content-actions-test.js

+30-35
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,24 @@ it("insert query for text action", function() {
1919
console.log(util.inspect(query, {
2020
depth: 4
2121
}));
22-
assert.deepEqual(query, [{
23-
'$': 'INSERT INTO "texts" ( "id", "from", "to", "time", "text", "thread", "title", "tags", "mentions", "upvoters", "flaggers", "updatetime", "updater" ) VALUES ( ${id}, ${from}, ${to}, ${time}, ${text}, ${thread}, ${title}, ${tags}, ${mentions}, ${upvoters}, ${flaggers}, ${updatetime}, ${updater} )',
24-
id: 'sasw4efsdewrewrrcdswerewqwe3432',
25-
from: 'testinguser',
26-
to: 'scrollback',
27-
time: new Date(1433852225717),
28-
text: 'testing message',
29-
thread: '32332hhhkhh23h3h2g432hg42',
30-
title: undefined,
31-
tags: [],
32-
mentions: undefined,
33-
upvoters: [],
34-
flaggers: [],
35-
updatetime: new Date(1433852225717),
36-
updater: 'testinguser'
37-
},
38-
{
39-
'$': 'UPDATE threads SET updatetime=${updatetime}, updater=${updater}, length=length+1, concerns = concerns || (SELECT array_agg(a.n) FROM (VALUES $(concerns)) AS a(n) WHERE NOT (threads.concerns @> ARRAY[a.n])) WHERE id=${id}',
40-
updatetime: new Date(1433852225717),
41-
updater: 'testinguser',
42-
concerns: [['testinguser'], [undefined]],
43-
id: '32332hhhkhh23h3h2g432hg42'
44-
}], "wrong query for text action");
22+
assert.deepEqual(query, [ { '$': 'INSERT INTO "texts" ( "id", "from", "to", "time", "text", "thread", "title", "tags", "mentions", "upvoters", "flaggers", "updatetime", "updater" ) VALUES ( ${id}, ${from}, ${to}, ${time}, ${text}, ${thread}, ${title}, ${tags}, ${mentions}, ${upvoters}, ${flaggers}, ${updatetime}, ${updater} )',
23+
id: 'sasw4efsdewrewrrcdswerewqwe3432',
24+
from: 'testinguser',
25+
to: 'scrollback',
26+
time: new Date(1433852225717),
27+
text: 'testing message',
28+
thread: '32332hhhkhh23h3h2g432hg42',
29+
title: undefined,
30+
tags: [],
31+
mentions: undefined,
32+
upvoters: [],
33+
flaggers: [],
34+
updatetime: new Date(1433852225717),
35+
updater: 'testinguser' },
36+
{ '$': 'UPDATE threads SET updatetime=${updatetime}, updater=${updater}, length=length+1 WHERE id=${id}',
37+
updatetime: new Date(1433852225717),
38+
updater: 'testinguser',
39+
id: '32332hhhkhh23h3h2g432hg42' } ], "wrong query for text action");
4540
});
4641

4742
it("query for edit action(text)", function() {
@@ -56,8 +51,8 @@ it("query for edit action(text)", function() {
5651
console.log(util.inspect(query, {
5752
depth: 4
5853
}));
59-
assert.deepEqual(query, [ { '$': 'UPDATE "texts" SET "updateTime"=${updateTime}, "text"=${text} WHERE id=${id}',
60-
updateTime: new Date(1433852225717),
54+
assert.deepEqual(query, [ { '$': 'UPDATE "texts" SET "updatetime"=${updatetime}, "text"=${text} WHERE id=${id}',
55+
updatetime: new Date(1433852225717),
6156
text: 'edit testing message',
6257
id: undefined } ], "wrong Query for editing a text");
6358
});
@@ -74,12 +69,12 @@ it("query for edit action(tags)", function() {
7469
console.log(util.inspect(query, {
7570
depth: 4
7671
}));
77-
assert.deepEqual(query, [ { '$': 'UPDATE "texts" SET "updateTime"=${updateTime}, "tags"=${tags} WHERE id=${id}',
78-
updateTime: new Date(1433852225717),
72+
assert.deepEqual(query, [ { '$': 'UPDATE "texts" SET "updatetime"=${updatetime}, "tags"=${tags} WHERE id=${id}',
73+
updatetime: new Date(1433852225717),
7974
tags: [ 'hidden' ],
8075
id: undefined },
81-
{ '$': 'UPDATE "threads" SET "updateTime"=${updateTime}, "tags"=${tags} WHERE id=${id}',
82-
updateTime: new Date(1433852225717),
76+
{ '$': 'UPDATE "threads" SET "updatetime"=${updatetime}, "tags"=${tags} WHERE id=${id}',
77+
updatetime: new Date(1433852225717),
8378
tags: [ 'hidden' ],
8479
id: undefined } ], "wrong Query for editing tag");
8580
});
@@ -98,12 +93,12 @@ it("query for edit action(title with tags)", function() {
9893
console.log(util.inspect(query, {
9994
depth: 4
10095
}));
101-
assert.deepEqual(query, [ { '$': 'UPDATE "texts" SET "updateTime"=${updateTime}, "tags"=${tags} WHERE id=${id}',
102-
updateTime: new Date(1433852225717),
96+
assert.deepEqual(query, [ { '$': 'UPDATE "texts" SET "updatetime"=${updatetime}, "tags"=${tags} WHERE id=${id}',
97+
updatetime: new Date(1433852225717),
10398
tags: [ 'abbusive' ],
10499
id: '324hhg382t43g4372g4u324' },
105-
{ '$': 'UPDATE "threads" SET "updateTime"=${updateTime}, "title"=${title}, "tags"=${tags} WHERE id=${id}',
106-
updateTime: new Date(1433852225717),
100+
{ '$': 'UPDATE "threads" SET "updatetime"=${updatetime}, "title"=${title}, "tags"=${tags} WHERE id=${id}',
101+
updatetime: new Date(1433852225717),
107102
title: 'editing the tittle',
108103
tags: [ 'abbusive' ],
109104
id: '324hhg382t43g4372g4u324' } ], "wrong Query for editing a title");
@@ -122,8 +117,8 @@ it("query for edit action(title)", function() {
122117
console.log(util.inspect(query, {
123118
depth: 4
124119
}));
125-
assert.deepEqual(query, [ { '$': 'UPDATE "threads" SET "updateTime"=${updateTime}, "title"=${title} WHERE id=${id}',
126-
updateTime: new Date(1433852225717),
120+
assert.deepEqual(query, [ { '$': 'UPDATE "threads" SET "updatetime"=${updatetime}, "title"=${title} WHERE id=${id}',
121+
updatetime: new Date(1433852225717),
127122
title: 'editing the tittle',
128123
id: '324hhg382t43g4372g4u324' } ], "wrong Query for editing a title");
129124
});

storage/test/entityActions-test.js renamed to storage/test/entity-actions-test.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,26 @@ describe("Insert Query: ", function() {
3232
depth: 4
3333
}));
3434

35-
assert.deepEqual(query, [{
36-
'$': 'INSERT INTO entities(id, identities, type, description, color, picture, createtime, timezone, locale, params, guides, terms) VALUES (${id}, ${identities}, $(values), to_tsvector(\'english\', ${terms}))',
37-
values: ['room',
35+
assert.deepEqual(query, [ { '$': 'INSERT INTO entities(id, identities, type, description, color, picture, createtime, timezone, locale, params, guides, terms) VALUES (${id}, ${identities}, $(values), to_tsvector(\'english\', ${terms}))',
36+
values:
37+
[ 'room',
3838
'This is a room.',
3939
0,
4040
'http://pic.com/abc.gif',
4141
new Date(1403947387876),
4242
0,
4343
'',
44-
{
45-
ha: 43
46-
},
47-
{
48-
hey: 4
49-
}],
50-
terms: 'roomid1 This is a room.',
51-
id: 'roomid1',
52-
identities: []
53-
},
54-
{
55-
'$': 'INSERT INTO relations(room, user, role, roletime) VALUES ($(values))',
56-
values: ['roomid1',
44+
{ ha: 43 },
45+
{ hey: 4 } ],
46+
terms: 'roomid1 This is a room.',
47+
id: 'roomid1',
48+
identities: [] },
49+
{ '$': 'INSERT INTO relations(room, "user", role, roletime) VALUES ($(values))',
50+
values:
51+
[ 'roomid1',
5752
'userid1',
5853
'owner',
59-
new Date(1403947387876)]
60-
}], "Wrong querry for room");
54+
new Date(1403947387876) ] } ], "Wrong querry for room");
6155
});
6256

6357
it("should make an insert query for user", function() {

storage/test/noteActions-test.js renamed to storage/test/note-actions-test.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,36 @@ it("notification query test", function() {
2121
console.log(util.inspect(query, {
2222
depth: 4
2323
}));
24-
assert.deepEqual(query, [ { '$': 'UPDATE "notes" SET "user"=${user}, "action"=${action}, "group"=${group}, "notetype"=${notetype}, "ref"=${ref}, "readTime"=${readTime}',
24+
assert.deepEqual(query, [ { '$': 'UPDATE "notes" SET "readtime"=${readtime} WHERE "user"=${user} AND "ref"=${ref} AND "group"=${group}',
25+
readtime: new Date(1433856224914),
2526
user: 'user1',
26-
action: 'text',
27-
group: 'scrollback',
28-
notetype: 'mention',
2927
ref: '4egwqyt326gewe23',
30-
readTime: new Date(1433856224914) } ], "wrong querry");
28+
group: 'scrollback' } ], "wrong querry");
3129
});
3230

3331
it("notification query test(type text)", function() {
3432
var query = note({
3533
type: "text",
3634
note: {
37-
group: "scrollback",
38-
data: {
39-
tittle: "some titile",
35+
mention: { group: "scrollback", data: {
36+
title: "some titile",
4037
text: "some text",
4138
from: "officer"
42-
}
39+
}},
40+
reply: {}
4341
},
4442
user: {
4543
id: "user1"
4644
},
4745
notify: {
48-
"testinguser": {score: 4, noteType: "mention"},
49-
"sbtestinguser": {score: 4, noteType: "thread"},
50-
"user1": {score: 4, noteType: "reply"},
51-
"user2": {score: 4, noteType: "mention"}
46+
"testinguser": {
47+
mention: 4,
48+
reply: 3
49+
}
5250
},
51+
occupants: [
52+
{ id: "chandrakant" }
53+
],
5354
noteType: "thread",
5455
ref: "someTextId",
5556
time: 1433856224914,
@@ -58,23 +59,20 @@ it("notification query test(type text)", function() {
5859
console.log(util.inspect(query, {
5960
depth: 4
6061
}));
61-
assert.deepEqual(query, [ { '$': 'INSERT INTO "notes" ( "user", "action", "ref", "notetype", "group", "score", "time", "notedata" ) VALUES ( ${user}, ${action}, ${ref}, ${notetype}, ${group}, ${score}, ${time}, ${notedata}), (${user_1}, ${action}, ${ref}, ${notetype_1}, ${group}, ${score}, ${time_1}, ${notedata}), (${user_2}, ${action}, ${ref}, ${notetype_2}, ${group}, ${score}, ${time_2}, ${notedata}), (${user_3}, ${action}, ${ref}, ${notetype}, ${group}, ${score}, ${time_3}, ${notedata} )',
62+
assert.deepEqual(query, [ { '$': 'INSERT INTO "notes" ( "user", "action", "ref", "notetype", "group", "score", "time", "notedata" ) VALUES ( ${user}, ${action}, ${ref}, ${notetype}, ${group}, ${score}, ${time}, ${notedata}), (${user}, ${action}, ${ref}, ${notetype_1}, ${group_1}, ${score_1}, ${time_1}, ${notedata_1} )',
6263
user: 'testinguser',
6364
action: 'text',
6465
ref: '4egwqyt326gewe23',
6566
notetype: 'mention',
6667
group: 'scrollback',
6768
score: 4,
6869
time: new Date(1433856224914),
69-
notedata: { tittle: 'some titile', text: 'some text', from: 'officer' },
70-
user_1: 'sbtestinguser',
71-
notetype_1: 'thread',
70+
notedata: {},
71+
notetype_1: 'reply',
72+
group_1: undefined,
73+
score_1: 3,
7274
time_1: new Date(1433856224914),
73-
user_2: 'user1',
74-
notetype_2: 'reply',
75-
time_2: new Date(1433856224914),
76-
user_3: 'user2',
77-
time_3: new Date(1433856224914) } ], "wrong query for notification of text action");
75+
notedata_1: {} } ], "wrong query for notification of text action");
7876
});
7977

8078
it("notification query test(without notify property)", function() {

storage/test/noteQueries-test.js renamed to storage/test/note-queries-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ it("note query test", function(){
1313
});
1414

1515
console.log(query);
16-
assert.deepEqual(query, { '$': 'SELECT "action", "notetype", "group", MAX("score") as "score", MAX("time") AS "time", COUNT(*) AS "count", CASE WHEN MAX(COALESCE(readtime, \'2050-01-01\')) = \'2050-01-01\'THEN NULL ELSE MAX(readtime) END AS readtime FROM notes WHERE "user"=${user} AND dismissTime IS NULL GROUP BY "action", "notetype", "group"',
16+
assert.deepEqual(query, { '$': 'SELECT "ref", "notetype", "user", "score", "notedata", "group", "time", "count" FROM (SELECT *,COUNT(*) OVER (PARTITION BY "user", "notetype", "group" ) "count",RANK() OVER (PARTITION BY "user", "notetype", "group" ORDER BY "time" DESC) timeRank FROM notes WHERE "user" = ${user} AND dismisstime IS NULL) t WHERE "count" <= 3 OR timeRank = 1;',
1717
user: 'userid1' }, "wrong query");
1818
});
1919

0 commit comments

Comments
 (0)