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

Added title normalization and tests for wiktionary #1078

Merged
merged 5 commits into from
Oct 29, 2018

Conversation

clarakosi
Copy link
Member

@clarakosi clarakosi commented Oct 26, 2018

Modified title in lib/normalize_title_filter.js to check for term in wiktionary before defaulting to title

Added tests to check case sensitivty and namespaces in wiktionary

Added wiktionary url to test/utils/server.js

Modified v1/definition.yaml to register the filter

Bug: T207904

Modified title in lib/normalize_title_filter.js to check for term in wiktionary before defaulting to title

Added tests to check case sensitivty and namespaces in wiktionary

Added wiktionary url to test/utils/server.js

Modified v1/definition.yaml to register the filter
Copy link
Contributor

@Pchelolo Pchelolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little bit of nit picks

@@ -29,6 +29,7 @@ module.exports = (hyper, req, next, options, specInfo) => {
}
});
}
rp.title = rp[options.title] ? rp[options.title] : rp.title;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. rp[options.title] || rp.title is nicer
  2. if options.title is undefined we'd be in trouble. so we need to go
    (options.title && rp[options.title]) || rp.title the brackets are not really needed, but it's easier to read without thinking.

@@ -9,6 +9,57 @@ describe('redirects', () => {
before(() => { return server.start(); });

describe('', () => {
it('should direct to a lowercase version of a title in wiktionary', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REdirect

});
});

it('should direct to an uppercase version of a title in wiktionary', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

Updated lib/normalize_title_filter.js to better follow format of lib/mwUtil.js

Modified lib/mwUtil.js to use {term} if present

Removed previous wiktionary test and replaced with one test that checks filter
Copy link
Contributor

@Pchelolo Pchelolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, sorry to say that, but it's a step to a wrong direction 😭

lib/mwUtil.js Outdated
@@ -341,7 +341,8 @@ mwUtil.createRelativeTitleRedirect = (path, req, options) => {
const backString = Array.apply(null, { length: pathSuffixCount }).map(() => '../').join('');
let location;
if (!options.dropPathAfterTitle) {
const pathPatternAfterTitle = path.substring(path.indexOf('{title}') - 1);
let pathPatternAfterTitle = path.substring(path.indexOf(`{${titleParamName}`) - 1);
pathPatternAfterTitle = pathPatternAfterTitle.replace(/term/, 'title');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way! This is super specific to the case that we have here right now. What if we're gonna have a different endpoint in the future where we decide to call the page title 'ugabugafoobarxxyyblombalabam' - we would need to replace that with 'title' as well.

This is a utility function, and it does take titleParamName as an option, so it has to work correctly whatever the titleParamName was provided to it right? Now it will only work if it's 'title' or a 'term'

@@ -29,6 +29,7 @@ module.exports = (hyper, req, next, options, specInfo) => {
}
});
}
rp.title = (options.title && rp[options.title]) || rp.title;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our overall goal here is to get rid of the hard-coded property name title right? So why are we assigning the request parameter title? We know that that the page name that we need to normalize will be located inside the options.title property right?

Also, having the options property named title is a bit confusing isn't it? now we have so many titles in the code that it's hard to understand which one refers to what. Would it be more understandable if the options property be called 'titleParamName' here as well as in the utility function?

In v1/definition.yaml updated title to title_param_name to better track code

In lib/mwUtil.js and lib/normalize_title_filter.js: changed hard coded title to be more dynamic towards the passed in variable
it('should redirect to a normalized version of a title', () => {
return preq.get({
uri: `${server.config.bucketURL}/html/Main%20Page?test=mwAQ`,
followRedirect: false
})
.then((res) => {
console.log(res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups...

@Pchelolo
Copy link
Contributor

That's what we're talking about! but you forgot a console.log in the test. Otherwise LGTM

@Pchelolo
Copy link
Contributor

Ok, let's ait for travis

@Pchelolo Pchelolo merged commit 8974d1a into wikimedia:master Oct 29, 2018
Copy link
Contributor

@d00rman d00rman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work @clarakosi! 👍

lib/mwUtil.js Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants