Skip to content

Commit

Permalink
refactor(contents): update tests URL and a variable scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafatcb committed Apr 20, 2024
1 parent a4ef786 commit e3e3b73
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion models/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
24 changes: 12 additions & 12 deletions tests/integration/api/v1/contents/[username]/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
});

Expand All @@ -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`,
},
});

Expand Down Expand Up @@ -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`,
},
});

Expand Down Expand Up @@ -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`,
},
});

Expand Down
46 changes: 23 additions & 23 deletions tests/integration/api/v1/contents/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ['<http://localhost:3000/api/v1/contents?strategy=relevant&page=1&per_page=30>; 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,
Expand Down Expand Up @@ -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`,
},
});

Expand Down Expand Up @@ -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`,
},
});

Expand Down Expand Up @@ -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`,
},
});

Expand Down Expand Up @@ -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`,
},
});

Expand All @@ -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`,
},
});

Expand All @@ -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`,
},
});

Expand Down Expand Up @@ -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`,
},
});

Expand Down
20 changes: 10 additions & 10 deletions tests/integration/api/v1/contents/rss/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ describe('GET /recentes/rss', () => {
<rss version="2.0">
<channel>
<title>TabNews</title>
<link>http://localhost:3000/recentes/rss</link>
<link>${orchestrator.webserverUrl}/recentes/rss</link>
<description>Conteúdos para quem trabalha com Programação e Tecnologia</description>
<lastBuildDate>${lastBuildDateFromResponseBody}</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>pt</language>
<image>
<title>TabNews</title>
<url>http://localhost:3000/favicon-mobile.png</url>
<link>http://localhost:3000/recentes/rss</link>
<url>${orchestrator.webserverUrl}/favicon-mobile.png</url>
<link>${orchestrator.webserverUrl}/recentes/rss</link>
</image>
</channel>
</rss>`);
Expand Down Expand Up @@ -84,29 +84,29 @@ describe('GET /recentes/rss', () => {
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>TabNews</title>
<link>http://localhost:3000/recentes/rss</link>
<link>${orchestrator.webserverUrl}/recentes/rss</link>
<description>Conteúdos para quem trabalha com Programação e Tecnologia</description>
<lastBuildDate>${new Date(secondRootContent.published_at).toUTCString()}</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>pt</language>
<image>
<title>TabNews</title>
<url>http://localhost:3000/favicon-mobile.png</url>
<link>http://localhost:3000/recentes/rss</link>
<url>${orchestrator.webserverUrl}/favicon-mobile.png</url>
<link>${orchestrator.webserverUrl}/recentes/rss</link>
</image>
<item>
<title><![CDATA[Conteúdo #2 (mais novo)]]></title>
<link>http://localhost:3000/${secondRootContent.owner_username}/${secondRootContent.slug}</link>
<guid>http://localhost:3000/${secondRootContent.owner_username}/${secondRootContent.slug}</guid>
<link>${orchestrator.webserverUrl}/${secondRootContent.owner_username}/${secondRootContent.slug}</link>
<guid>${orchestrator.webserverUrl}/${secondRootContent.owner_username}/${secondRootContent.slug}</guid>
<pubDate>${new Date(secondRootContent.published_at).toUTCString()}</pubDate>
<description><![CDATA[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 quant...]]></description>
<content:encoded><![CDATA[<div class="markdown-body"><p>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.</p></div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Conteúdo #1 (mais antigo)]]></title>
<link>http://localhost:3000/${firstRootContent.owner_username}/${firstRootContent.slug}</link>
<guid>http://localhost:3000/${firstRootContent.owner_username}/${firstRootContent.slug}</guid>
<link>${orchestrator.webserverUrl}/${firstRootContent.owner_username}/${firstRootContent.slug}</link>
<guid>${orchestrator.webserverUrl}/${firstRootContent.owner_username}/${firstRootContent.slug}</guid>
<pubDate>${new Date(firstRootContent.published_at).toUTCString()}</pubDate>
<description><![CDATA[Corpo com HTML É importante lidar corretamente com o HTML, incluindo estilos especiais do GFM.]]></description>
<content:encoded><![CDATA[<div class="markdown-body"><h1 id="${defaultUser.username.toLowerCase()}-content-corpo-com-html">Corpo com HTML</h1><p>É <strong>importante</strong> lidar corretamente com o <code>HTML</code>, incluindo estilos <del>especiais</del> do <code>GFM</code>.</p></div>]]></content:encoded>
Expand Down

0 comments on commit e3e3b73

Please sign in to comment.