diff --git a/models/content.js b/models/content.js index 20a24f2f8..3713e55c0 100644 --- a/models/content.js +++ b/models/content.js @@ -12,13 +12,13 @@ import queries from 'queries/rankingQueries'; async function findAll(values = {}, options = {}) { values = validateValues(values); await replaceOwnerUsernameWithOwnerId(values); - const offset = (values.page - 1) * values.per_page; const query = { values: [], }; if (!values.count) { + const offset = (values.page - 1) * values.per_page; query.values = [values.limit || values.per_page, offset]; } diff --git a/tests/integration/api/v1/contents/[username]/get.test.js b/tests/integration/api/v1/contents/[username]/get.test.js index 8033c29b3..e8bbf13e4 100644 --- a/tests/integration/api/v1/contents/[username]/get.test.js +++ b/tests/integration/api/v1/contents/[username]/get.test.js @@ -558,21 +558,21 @@ describe('GET /api/v1/contents/[username]', () => { per_page: '30', rel: 'first', strategy: 'new', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=new&page=1&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=new&page=1&per_page=30`, }, next: { page: '2', per_page: '30', rel: 'next', strategy: 'new', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=new&page=2&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=new&page=2&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'new', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=new&page=2&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=new&page=2&per_page=30`, }, }); @@ -599,21 +599,21 @@ describe('GET /api/v1/contents/[username]', () => { per_page: '30', rel: 'first', strategy: 'new', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=new&page=1&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=new&page=1&per_page=30`, }, prev: { page: '1', per_page: '30', rel: 'prev', strategy: 'new', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=new&page=1&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=new&page=1&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'new', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=new&page=2&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=new&page=2&per_page=30`, }, }); @@ -700,21 +700,21 @@ describe('GET /api/v1/contents/[username]', () => { per_page: '30', rel: 'first', strategy: 'relevant', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=relevant&page=1&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=relevant&page=1&per_page=30`, }, next: { page: '2', per_page: '30', rel: 'next', strategy: 'relevant', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=relevant&page=2&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=relevant&page=2&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'relevant', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=relevant&page=2&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=relevant&page=2&per_page=30`, }, }); @@ -743,21 +743,21 @@ describe('GET /api/v1/contents/[username]', () => { per_page: '30', rel: 'first', strategy: 'relevant', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=relevant&page=1&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=relevant&page=1&per_page=30`, }, prev: { page: '1', per_page: '30', rel: 'prev', strategy: 'relevant', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=relevant&page=1&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=relevant&page=1&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'relevant', - url: `http://localhost:3000/api/v1/contents/${defaultUser.username}?strategy=relevant&page=2&per_page=30`, + url: `${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}?strategy=relevant&page=2&per_page=30`, }, }); diff --git a/tests/integration/api/v1/contents/get.test.js b/tests/integration/api/v1/contents/get.test.js index afe705def..677914d39 100644 --- a/tests/integration/api/v1/contents/get.test.js +++ b/tests/integration/api/v1/contents/get.test.js @@ -39,7 +39,7 @@ describe('GET /api/v1/contents', () => { 'access-control-allow-headers': [ 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version', ], - link: ['; rel="first"'], + link: [`<${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=1&per_page=30>; rel="first"`], 'x-pagination-total-rows': ['0'], 'content-type': ['application/json; charset=utf-8'], etag: responseHeaders.etag, @@ -374,21 +374,21 @@ describe('GET /api/v1/contents', () => { per_page: '30', rel: 'first', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=1&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=1&per_page=30`, }, next: { page: '2', per_page: '30', rel: 'next', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=2&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=2&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=2&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=2&per_page=30`, }, }); @@ -735,21 +735,21 @@ describe('GET /api/v1/contents', () => { per_page: '30', rel: 'first', strategy: 'relevant', - url: 'http://localhost:3000/api/v1/contents?strategy=relevant&page=1&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=1&per_page=30`, }, next: { page: '2', per_page: '30', rel: 'next', strategy: 'relevant', - url: 'http://localhost:3000/api/v1/contents?strategy=relevant&page=2&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=2&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'relevant', - url: 'http://localhost:3000/api/v1/contents?strategy=relevant&page=2&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=2&per_page=30`, }, }); @@ -805,21 +805,21 @@ describe('GET /api/v1/contents', () => { per_page: '30', rel: 'first', strategy: 'relevant', - url: 'http://localhost:3000/api/v1/contents?strategy=relevant&page=1&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=1&per_page=30`, }, prev: { page: '1', per_page: '30', rel: 'prev', strategy: 'relevant', - url: 'http://localhost:3000/api/v1/contents?strategy=relevant&page=1&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=1&per_page=30`, }, last: { page: '2', per_page: '30', rel: 'last', strategy: 'relevant', - url: 'http://localhost:3000/api/v1/contents?strategy=relevant&page=2&per_page=30', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=relevant&page=2&per_page=30`, }, }); @@ -859,21 +859,21 @@ describe('GET /api/v1/contents', () => { per_page: '3', rel: 'first', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=1&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=1&per_page=3`, }, next: { page: '2', per_page: '3', rel: 'next', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=2&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=2&per_page=3`, }, last: { page: '3', per_page: '3', rel: 'last', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=3&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=3&per_page=3`, }, }); @@ -896,28 +896,28 @@ describe('GET /api/v1/contents', () => { per_page: '3', rel: 'first', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=1&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=1&per_page=3`, }, prev: { page: '1', per_page: '3', rel: 'prev', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=1&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=1&per_page=3`, }, next: { page: '3', per_page: '3', rel: 'next', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=3&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=3&per_page=3`, }, last: { page: '3', per_page: '3', rel: 'last', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=3&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=3&per_page=3`, }, }); @@ -940,21 +940,21 @@ describe('GET /api/v1/contents', () => { per_page: '3', rel: 'first', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=1&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=1&per_page=3`, }, prev: { page: '2', per_page: '3', rel: 'prev', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=2&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=2&per_page=3`, }, last: { page: '3', per_page: '3', rel: 'last', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=3&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=3&per_page=3`, }, }); @@ -1012,21 +1012,21 @@ describe('GET /api/v1/contents', () => { per_page: '3', rel: 'first', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=1&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=1&per_page=3`, }, prev: { page: '3', per_page: '3', rel: 'prev', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=3&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=3&per_page=3`, }, last: { page: '3', per_page: '3', rel: 'last', strategy: 'new', - url: 'http://localhost:3000/api/v1/contents?strategy=new&page=3&per_page=3', + url: `${orchestrator.webserverUrl}/api/v1/contents?strategy=new&page=3&per_page=3`, }, }); diff --git a/tests/integration/api/v1/contents/rss/get.test.js b/tests/integration/api/v1/contents/rss/get.test.js index 8f884d9b7..ef8b44251 100644 --- a/tests/integration/api/v1/contents/rss/get.test.js +++ b/tests/integration/api/v1/contents/rss/get.test.js @@ -32,7 +32,7 @@ describe('GET /recentes/rss', () => { TabNews - http://localhost:3000/recentes/rss + ${orchestrator.webserverUrl}/recentes/rss Conteúdos para quem trabalha com Programação e Tecnologia ${lastBuildDateFromResponseBody} https://validator.w3.org/feed/docs/rss2.html @@ -40,8 +40,8 @@ describe('GET /recentes/rss', () => { pt TabNews - http://localhost:3000/favicon-mobile.png - http://localhost:3000/recentes/rss + ${orchestrator.webserverUrl}/favicon-mobile.png + ${orchestrator.webserverUrl}/recentes/rss `); @@ -84,7 +84,7 @@ describe('GET /recentes/rss', () => { TabNews - http://localhost:3000/recentes/rss + ${orchestrator.webserverUrl}/recentes/rss Conteúdos para quem trabalha com Programação e Tecnologia ${new Date(secondRootContent.published_at).toUTCString()} https://validator.w3.org/feed/docs/rss2.html @@ -92,21 +92,21 @@ describe('GET /recentes/rss', () => { pt TabNews - http://localhost:3000/favicon-mobile.png - http://localhost:3000/recentes/rss + ${orchestrator.webserverUrl}/favicon-mobile.png + ${orchestrator.webserverUrl}/recentes/rss <![CDATA[Conteúdo #2 (mais novo)]]> - http://localhost:3000/${secondRootContent.owner_username}/${secondRootContent.slug} - http://localhost:3000/${secondRootContent.owner_username}/${secondRootContent.slug} + ${orchestrator.webserverUrl}/${secondRootContent.owner_username}/${secondRootContent.slug} + ${orchestrator.webserverUrl}/${secondRootContent.owner_username}/${secondRootContent.slug} ${new Date(secondRootContent.published_at).toUTCString()}

Este é um corpo bastante longo, vamos ver como que a propriedade description irá reagir, pois por padrão ela deverá cortar após um número X de caracteres. Não vou tomar nota aqui da quantidade exata de caracteres, pois isso pode mudar ao longo do tempo.

]]>
<![CDATA[Conteúdo #1 (mais antigo)]]> - http://localhost:3000/${firstRootContent.owner_username}/${firstRootContent.slug} - http://localhost:3000/${firstRootContent.owner_username}/${firstRootContent.slug} + ${orchestrator.webserverUrl}/${firstRootContent.owner_username}/${firstRootContent.slug} + ${orchestrator.webserverUrl}/${firstRootContent.owner_username}/${firstRootContent.slug} ${new Date(firstRootContent.published_at).toUTCString()}

Corpo com HTML

É importante lidar corretamente com o HTML, incluindo estilos especiais do GFM.

]]>