Skip to content

Commit

Permalink
Merge pull request #127 from partio-scout/feature/hashtag-textsearch
Browse files Browse the repository at this point in the history
Feature/hashtag textsearch
  • Loading branch information
googol authored Jul 17, 2016
2 parents 6142c41 + d332676 commit 552d13a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/client/actions/ParticipantActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function getParticipantActions(alt, participantResource) {

return dispatch => {
dispatch();
participantResource.findAll(`filter=${JSON.stringify(filters)}`)
participantResource.findAll(`filter=${encodeURIComponent(JSON.stringify(filters))}`)
.then(participantList => this.participantListUpdated(participantList),
err => this.participantListUpdateFailed(err));
};
Expand All @@ -59,7 +59,7 @@ export function getParticipantActions(alt, participantResource) {
loadParticipantCount(filter) {
return dispatch => {
dispatch();
participantResource.raw('get', 'count', { filters: `where=${JSON.stringify(filter)}` })
participantResource.raw('get', 'count', { filters: `where=${encodeURIComponent(JSON.stringify(filter))}` })
.then(response => this.participantCountUpdated(response.count),
err => this.participantCountUpdateFailed(err));
};
Expand Down
6 changes: 4 additions & 2 deletions src/common/models/participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default function (Participant) {

function constructTextSearchArray(string) {
const stripRegex = function(s) {
// Remove all charactes except alphabets (with umlauts and accents), numbers and dash
return s.replace(/[^A-zÀ-úÀ-ÿ0-9-]/ig, '');
// Remove all charactes except alphabets (with umlauts and accents), numbers, dash and hashtag
return s.replace(/[^A-zÀ-úÀ-ÿ0-9-#]/ig, '');
};

function nameQuery(string, string2) {
Expand All @@ -46,6 +46,8 @@ export default function (Participant) {

or.push({ staffPosition: { regexp: `/${stripRegex(string)}/i` } });
or.push({ staffPositionInGenerator: { regexp: `/${stripRegex(string)}/i` } });
or.push({ campOfficeNotes: { regexp: `/${stripRegex(string)}/i` } });
or.push({ editableInfo: { regexp: `/${stripRegex(string)}/i` } });

const splitted = string.split(' ', 2);

Expand Down
29 changes: 26 additions & 3 deletions test/text-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Text search', () => {
'memberNumber': 123,
'staffPosition': null,
'staffPositionInGenerator': 'Tiskari',
'editableInfo': 'Muokattava teksti',
},
{
'participantId': 2,
Expand All @@ -42,6 +43,7 @@ describe('Text search', () => {
'memberNumber': 345,
'staffPosition': 'Jumppaohjaaja',
'staffPositionInGenerator': null,
'campOfficeNotes': 'Leiritoimiston jutut',
},
{
'participantId': 3,
Expand All @@ -56,7 +58,7 @@ describe('Text search', () => {
'ageGroup': 'seikkailija',
'memberNumber': 859,
'staffPosition': 'Kaivaja',
'staffPositionInGenerator': 'Kaivuumies',
'staffPositionInGenerator': '#Tiskari',
},
];

Expand Down Expand Up @@ -87,7 +89,7 @@ describe('Text search', () => {

function queryParticipants(filter, accessToken) {
return request(app)
.get(`/api/participants/?access_token=${accessToken}&filter={"where":${JSON.stringify(filter)},"skip":0,"limit":20}`)
.get(`/api/participants/?access_token=${accessToken}&filter={"where":${encodeURIComponent(JSON.stringify(filter))},"skip":0,"limit":20}`)
.expect(200);
}

Expand Down Expand Up @@ -171,12 +173,33 @@ describe('Text search', () => {
it('Query with staff position in generator', () =>
queryParticipants({ 'textSearch':'Tiskari' }, accessToken)
.then(res => {
expectParticipants([ 'Teemu' ], res.body);
expectParticipants([ 'Teemu', 'Jussi' ], res.body);
})
);

it('Query with partial staff position', () =>
queryParticipants({ 'textSearch':'tisk' }, accessToken)
.then(res => {
expectParticipants([ 'Teemu', 'Jussi' ], res.body);
})
);

it('Query with hashtag', () =>
queryParticipants({ 'textSearch':'#Tiskari' }, accessToken)
.then(res => {
expectParticipants([ 'Jussi' ], res.body);
})
);

it('Query with camp office notes', () =>
queryParticipants({ 'textSearch':'Leiritoimisto' }, accessToken)
.then(res => {
expectParticipants([ 'Tero' ], res.body);
})
);

it('Query with editable info', () =>
queryParticipants({ 'textSearch':'Muokattava' }, accessToken)
.then(res => {
expectParticipants([ 'Teemu' ], res.body);
})
Expand Down

0 comments on commit 552d13a

Please sign in to comment.