Commit fc0d0dbf authored by Nacim Goura's avatar Nacim Goura

fix bug test search

parent 7e49baee
......@@ -6,34 +6,39 @@ import moment from 'moment';
import testSearchCollection from '/imports/api/testSearch/testSearchCollection';
import { searchWebsite } from '/imports/api/search/methods';
export function addTest(data) {
export function addTest(newTest) {
// test data
check(data, Object);
testSearchCollection.simpleSchema().validate(data);
// replace https by http
data.urlExpected = decodeURI(_.replace(data.urlExpected, 'https', 'http'));
check(newTest, Object);
if (!newTest.userId) {
newTest.userId = Meteor.userId();
}
newTest.createdAt = moment().toDate();
testSearchCollection.simpleSchema().validate(newTest);
// call search
searchWebsite({ searchTerm: data.searchTerm })
searchWebsite({ searchTerm: newTest.searchTerm })
.then((results) => {
_.forEach(results.list, (result, index) => {
if (data.urlExpected === result.url) {
data.urlPosition = index + 1;
if (newTest.urlExpected === result.url) {
newTest.urlPosition = index + 1;
}
});
const oldTest = testSearchCollection.findOne({ searchTerm: data.searchTerm });
const oldTest = testSearchCollection.findOne({
searchTerm: newTest.searchTerm,
userId: Meteor.userId(),
});
if (oldTest) {
testSearchCollection.update(oldTest._id, {
testSearchCollection.update({ _id: oldTest._id }, {
$set: {
urlPosition: data.urlPosition,
createdAt: moment().toDate(),
urlPosition: newTest.urlPosition,
createdAt: newTest.createdAt,
},
});
} else {
testSearchCollection.insert(data);
testSearchCollection.insert(newTest);
}
}).catch((error) => {
console.error(error);
throw new Meteor.Error('Error', 'Erreur lors de la recherche', error);
});
}
......@@ -44,7 +49,7 @@ export function deleteTest(id) {
}
export function relaunchTest() {
const tests = testSearchCollection.find({}).fetch();
const tests = testSearchCollection.find({ userId: Meteor.userId() }).fetch();
_.forEach(tests, (test) => {
addTest(test);
});
......
......@@ -2,7 +2,6 @@
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import { Tracker } from 'meteor/tracker';
import moment from 'moment';
SimpleSchema.extendOptions(['autoform']);
......@@ -16,6 +15,9 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
_id: {
type: String,
required: false,
autoform: {
type: 'hidden',
},
},
searchTerm: {
type: String,
......@@ -24,15 +26,32 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
urlExpected: {
type: String,
label: 'Url attendu : ',
autoValue() {
if (this.isInsert) {
return this.value.replace('https', 'http');
}
},
},
urlPosition: {
type: Number,
required: false,
autoform: {
type: 'hidden',
},
},
createdAt: {
type: Date,
required: false,
defaultValue: moment().toDate(),
autoform: {
type: 'hidden',
},
},
userId: {
type: String,
autoform: {
type: 'hidden',
},
required: false,
},
}, { tracker: Tracker });
......
......@@ -8,6 +8,9 @@ new Tabular.Table({
name: 'testSearch',
collection: testSearchCollection,
columns: [
{
data: 'userId', title: 'userId',
},
{
data: 'searchTerm', title: 'Terme recherché',
},
......
......@@ -20,6 +20,9 @@
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading text-center">
......@@ -34,9 +37,6 @@
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading text-center">
......
......@@ -4,11 +4,7 @@
Tester le système de recherche :
{{#autoForm id="testSearchForm" class="form-inline" method="post" collection=testSearchCollection type="method" meteormethod="addTest" }}
{{> afQuickField name='searchTerm'}}
{{> afQuickField name='urlExpected'}}
<button type="submit" class="btn btn-success">Tester</button>
{{/autoForm}}
{{> quickForm id="testSearchForm" class="form-inline" schema=testSearchSchema buttonContent="Tester" type="method" meteormethod="addTest" }}
<div class="panel panel-default wrapper">
<div class="panel-heading text-center">
......
......@@ -7,7 +7,7 @@ import '/imports/tabular/configClient';
import './testSearch.html';
Template.testSearchTpl.helpers({
testSearchCollection: () => testSearchCollection,
testSearchSchema: () => testSearchCollection.simpleSchema(),
});
Template.testSearchTpl.events({
......
......@@ -37,7 +37,15 @@ const checkData = {
addMissingSpaces: true, // adds missing spaces after dots/colons/semicolons, unless it's URL
});
resultText = resultText.replace(/[Æ]/g, 'ae'); // .replace(/[\n\\/]/gm, ' ').replace(/[<br>]/gm, ' ').replace(/[^\S]{2,}/gm, ' ');
resultText = resultText.replace(/([a-z])([A-Z])/g, '$1 $2');
/**
* ajoute un espace avant un mot commencant par une majuscule pour que
* les mots ne soit pas collés sauf s'il s'agit d'un guillemet
*/
resultText = resultText.replace(/([^A-Z'`])([A-Z])/g, '$1 $2');
// remplace les caractères spéciaux
resultText = resultText.replace(/[\/<>_():\\«»"]/g, ' ');
// remplace les espaces et les retours à la ligne par un espace
resultText = resultText.replace(/(\s{2,})/g, ' ');
return unfancy(resultText);
},
......
#!/usr/bin/env bash
~/.nvm/nvm.sh use && cd ./.deploy/ && pm2-meteor deploy
source ~/.nvm/nvm.sh
source ~/.profile
source ~/.bashrc
nvm use
cd ./.deploy/
pm2-meteor deploy
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment