|
@@ -1006,4 +1006,143 @@ describe('read lists of ideas', () => {
|
1006
|
1006
|
});
|
1007
|
1007
|
});
|
1008
|
1008
|
});
|
|
1009
|
+
|
|
1010
|
+ describe('GET /ideas?filter[title][like]=string1,string2,string3', () => {
|
|
1011
|
+ let user0;
|
|
1012
|
+ // create and save testing data
|
|
1013
|
+ beforeEach(async () => {
|
|
1014
|
+ const data = {
|
|
1015
|
+ users: 2,
|
|
1016
|
+ verifiedUsers: [0],
|
|
1017
|
+ ideas: [ [{title:'idea-title1'}, 0], [{title:'idea-title2-keyword1'}, 0], [{title:'idea-title3-keyword2'}, 0], [{title:'idea-title4-keyword3'}, 0], [{title:'idea-title5-keyword2-keyword3'}, 0], [{title:'idea-title6-keyword1'}, 0], [{title:'idea-title7-keyword1-keyword4'}, 0] ]
|
|
1018
|
+ };
|
|
1019
|
+
|
|
1020
|
+ dbData = await dbHandle.fill(data);
|
|
1021
|
+
|
|
1022
|
+ [user0, ] = dbData.users;
|
|
1023
|
+ });
|
|
1024
|
+
|
|
1025
|
+ context('logged in', () => {
|
|
1026
|
+
|
|
1027
|
+ beforeEach(() => {
|
|
1028
|
+ agent = agentFactory.logged(user0);
|
|
1029
|
+ });
|
|
1030
|
+
|
|
1031
|
+ context('valid data', () => {
|
|
1032
|
+
|
|
1033
|
+ it('[find ideas with one word] 200 and return array of matched ideas', async () => {
|
|
1034
|
+
|
|
1035
|
+ // request
|
|
1036
|
+ const response = await agent
|
|
1037
|
+ .get('/ideas?filter[title][like]=keyword1')
|
|
1038
|
+ .expect(200);
|
|
1039
|
+
|
|
1040
|
+ // we should find 2 ideas...
|
|
1041
|
+ should(response.body).have.property('data').Array().length(3);
|
|
1042
|
+
|
|
1043
|
+ // sorted by creation date desc
|
|
1044
|
+ should(response.body.data.map(idea => idea.attributes.title))
|
|
1045
|
+ .eql(['idea-title2-keyword1','idea-title6-keyword1', 'idea-title7-keyword1-keyword4']);
|
|
1046
|
+
|
|
1047
|
+ });
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+ it('[find ideas with two words] 200 and return array of matched ideas', async () => {
|
|
1051
|
+
|
|
1052
|
+ // request
|
|
1053
|
+ const response = await agent
|
|
1054
|
+ .get('/ideas?filter[title][like]=keyword2,keyword3')
|
|
1055
|
+ .expect(200);
|
|
1056
|
+
|
|
1057
|
+ // we should find 4 ideas...
|
|
1058
|
+ should(response.body).have.property('data').Array().length(3);
|
|
1059
|
+
|
|
1060
|
+ // sorted by creation date desc
|
|
1061
|
+ should(response.body.data.map(idea => idea.attributes.title))
|
|
1062
|
+ .eql(['idea-title5-keyword2-keyword3', 'idea-title3-keyword2', 'idea-title4-keyword3']);
|
|
1063
|
+ });
|
|
1064
|
+
|
|
1065
|
+ it('[find ideas with word not present in any] 200 and return array of matched ideas', async () => {
|
|
1066
|
+
|
|
1067
|
+ // request
|
|
1068
|
+ const response = await agent
|
|
1069
|
+ .get('/ideas?filter[title][like]=keyword10')
|
|
1070
|
+ .expect(200);
|
|
1071
|
+
|
|
1072
|
+ // we should find 0 ideas...
|
|
1073
|
+ should(response.body).have.property('data').Array().length(0);
|
|
1074
|
+
|
|
1075
|
+ });
|
|
1076
|
+
|
|
1077
|
+ it('[pagination] offset and limit the results', async () => {
|
|
1078
|
+ const response = await agent
|
|
1079
|
+ .get('/ideas?filter[title][like]=keyword1&page[offset]=1&page[limit]=2')
|
|
1080
|
+ .expect(200);
|
|
1081
|
+
|
|
1082
|
+ // we should find 3 ideas
|
|
1083
|
+ should(response.body).have.property('data').Array().length(2);
|
|
1084
|
+
|
|
1085
|
+ // sorted by creation date desc
|
|
1086
|
+ should(response.body.data.map(idea => idea.attributes.title))
|
|
1087
|
+ .eql(['idea-title6-keyword1', 'idea-title7-keyword1-keyword4']);
|
|
1088
|
+ });
|
|
1089
|
+
|
|
1090
|
+ it('should be fine to provide a keyword which includes empty spaces and/or special characters', async () => {
|
|
1091
|
+ // request
|
|
1092
|
+ await agent
|
|
1093
|
+ .get('/ideas?filter[title][like]=keyword , aa,1-i')
|
|
1094
|
+ .expect(200);
|
|
1095
|
+ });
|
|
1096
|
+
|
|
1097
|
+ });
|
|
1098
|
+
|
|
1099
|
+ context('invalid data', () => {
|
|
1100
|
+
|
|
1101
|
+ it('[too many keywords] 400', async () => {
|
|
1102
|
+ await agent
|
|
1103
|
+ .get('/ideas?filter[title][like]=keyword1,keyword2,keyword3,keyword4,keyword5,keyword6,keyword7,keyword8,keyword9,keyword10,keyword11')
|
|
1104
|
+ .expect(400);
|
|
1105
|
+ });
|
|
1106
|
+
|
|
1107
|
+ it('[empty keywords] 400', async () => {
|
|
1108
|
+ await agent
|
|
1109
|
+ .get('/ideas?filter[title][like]=keyword1,')
|
|
1110
|
+ .expect(400);
|
|
1111
|
+ });
|
|
1112
|
+
|
|
1113
|
+ it('[too long keywords] 400', async () => {
|
|
1114
|
+ await agent
|
|
1115
|
+ .get(`/ideas?filter[title][like]=keyword1,${'a'.repeat(257)}`)
|
|
1116
|
+ .expect(400);
|
|
1117
|
+ });
|
|
1118
|
+
|
|
1119
|
+ it('[keywords spaces only] 400', async () => {
|
|
1120
|
+ await agent
|
|
1121
|
+ .get('/ideas?filter[title][like]= ,keyword2')
|
|
1122
|
+ .expect(400);
|
|
1123
|
+ });
|
|
1124
|
+
|
|
1125
|
+ it('[invalid pagination] 400', async () => {
|
|
1126
|
+ await agent
|
|
1127
|
+ .get('/ideas?filter[title][like]=keyword1&page[offset]=1&page[limit]=21')
|
|
1128
|
+ .expect(400);
|
|
1129
|
+ });
|
|
1130
|
+
|
|
1131
|
+ it('[unexpected query params] 400', async () => {
|
|
1132
|
+ await agent
|
|
1133
|
+ .get('/ideas?filter[title][like]=keyword1&additional[param]=3&page[offset]=1&page[limit]=3')
|
|
1134
|
+ .expect(400);
|
|
1135
|
+ });
|
|
1136
|
+ });
|
|
1137
|
+ });
|
|
1138
|
+
|
|
1139
|
+ context('not logged in', () => {
|
|
1140
|
+ it('403', async () => {
|
|
1141
|
+ await agent
|
|
1142
|
+ .get('/ideas?filter[title][like]=keyword1')
|
|
1143
|
+ .expect(403);
|
|
1144
|
+ });
|
|
1145
|
+ });
|
|
1146
|
+ });
|
|
1147
|
+
|
1009
|
1148
|
});
|