Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hashtag textsearch #127

Merged
merged 4 commits into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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