Skip to content

Commit

Permalink
feat(content): add type field to public content schema
Browse files Browse the repository at this point in the history
  • Loading branch information
aprendendofelipe committed Jul 11, 2024
1 parent ee3bd8c commit 3d159a9
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 7 deletions.
1 change: 1 addition & 0 deletions models/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ const schemas = {
'title',
'body',
'status',
'content_type',
'source_url',
'created_at',
'updated_at',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
tabcoins_credit: 0,
tabcoins_debit: 0,
status: childBranchBLevel1.status,
type: 'content',
source_url: childBranchBLevel1.source_url,
created_at: childBranchBLevel1.created_at.toISOString(),
updated_at: childBranchBLevel1.updated_at.toISOString(),
Expand All @@ -172,6 +173,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
tabcoins_credit: 0,
tabcoins_debit: 0,
status: childBranchBLevel2Content1.status,
type: 'content',
source_url: childBranchBLevel2Content1.source_url,
created_at: childBranchBLevel2Content1.created_at.toISOString(),
updated_at: childBranchBLevel2Content1.updated_at.toISOString(),
Expand All @@ -192,6 +194,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
tabcoins_credit: 0,
tabcoins_debit: 0,
status: childBranchBLevel2Content2.status,
type: 'content',
source_url: childBranchBLevel2Content2.source_url,
created_at: childBranchBLevel2Content2.created_at.toISOString(),
updated_at: childBranchBLevel2Content2.updated_at.toISOString(),
Expand All @@ -212,6 +215,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
title: childBranchALevel1.title,
body: childBranchALevel1.body,
status: childBranchALevel1.status,
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand All @@ -230,6 +234,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
title: childBranchALevel2.title,
body: childBranchALevel2.body,
status: childBranchALevel2.status,
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand All @@ -251,6 +256,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
tabcoins_credit: 0,
tabcoins_debit: 0,
status: childBranchALevel3.status,
type: 'content',
source_url: childBranchALevel3.source_url,
created_at: childBranchALevel3.created_at.toISOString(),
updated_at: childBranchALevel3.updated_at.toISOString(),
Expand Down Expand Up @@ -346,6 +352,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
title: childBranchBLevel2Content2.title,
body: childBranchBLevel2Content2.body,
status: childBranchBLevel2Content2.status,
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand All @@ -366,6 +373,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
title: childBranchBLevel2Content1.title,
body: childBranchBLevel2Content1.body,
status: childBranchBLevel2Content1.status,
type: 'content',
tabcoins: 0,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -436,6 +444,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
tabcoins_credit: 2,
tabcoins_debit: -1,
status: childBranchBLevel1.status,
type: 'content',
source_url: childBranchBLevel1.source_url,
created_at: childBranchBLevel1.created_at.toISOString(),
updated_at: childBranchBLevel1.updated_at.toISOString(),
Expand All @@ -453,6 +462,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
title: childBranchALevel1.title,
body: childBranchALevel1.body,
status: childBranchALevel1.status,
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand All @@ -471,6 +481,7 @@ describe('GET /api/v1/contents/[username]/[slug]/children', () => {
title: childBranchALevel2.title,
body: childBranchALevel2.body,
status: childBranchALevel2.status,
type: 'content',
tabcoins: 5,
tabcoins_credit: 4,
tabcoins_debit: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('GET /api/v1/contents/[username]/[slug]', () => {
title: 'Conteúdo publicamente disponível',
body: 'Conteúdo relevante deveria estar disponível para todos.',
status: 'published',
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -203,6 +204,7 @@ describe('GET /api/v1/contents/[username]/[slug]', () => {
title: 'Conteúdo root',
body: 'Body with relevant texts needs to contain a good amount of words',
status: 'published',
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -285,6 +287,7 @@ describe('GET /api/v1/contents/[username]/[slug]', () => {
title: null,
body: 'Conteúdo child',
status: 'published',
type: 'content',
tabcoins: 0,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -355,6 +358,7 @@ describe('GET /api/v1/contents/[username]/[slug]', () => {
title: null,
body: 'Conteúdo child',
status: 'published',
type: 'content',
tabcoins: 0,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -441,6 +445,7 @@ describe('GET /api/v1/contents/[username]/[slug]', () => {
title: 'Conteúdo com TabCoins',
body: 'Conteúdo que foi avaliado positiva e negativamente.',
status: 'published',
type: 'content',
tabcoins: 2,
tabcoins_credit: 3,
tabcoins_debit: -1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe('GET /api/v1/contents/[username]/[slug]/parent', () => {
body: 'Root - Body with relevant texts needs to contain a good amount of words',
children_deep_count: 1,
status: 'published',
type: 'content',
source_url: null,
published_at: rootContent.published_at.toISOString(),
created_at: rootContent.created_at.toISOString(),
Expand Down Expand Up @@ -287,6 +288,7 @@ describe('GET /api/v1/contents/[username]/[slug]/parent', () => {
body: 'Child content body Level 2 - relevant content',
children_deep_count: 1,
status: 'published',
type: 'content',
source_url: null,
published_at: childContentLevel2.published_at.toISOString(),
created_at: childContentLevel2.created_at.toISOString(),
Expand Down Expand Up @@ -354,6 +356,7 @@ describe('GET /api/v1/contents/[username]/[slug]/parent', () => {
body: '[Não disponível]',
children_deep_count: 0,
status: 'draft',
type: 'content',
source_url: null,
published_at: null,
created_at: childContentLevel2.created_at.toISOString(),
Expand Down Expand Up @@ -422,6 +425,7 @@ describe('GET /api/v1/contents/[username]/[slug]/parent', () => {
body: '[Não disponível]',
children_deep_count: 0,
status: 'deleted',
type: 'content',
source_url: null,
published_at: childContentLevel2.published_at.toISOString(),
created_at: childContentLevel2.created_at.toISOString(),
Expand Down Expand Up @@ -472,6 +476,7 @@ describe('GET /api/v1/contents/[username]/[slug]/parent', () => {
body: 'Root - Body with relevant texts needs to contain a good amount of words',
children_deep_count: 1,
status: 'published',
type: 'content',
source_url: null,
published_at: rootContent.published_at.toISOString(),
created_at: rootContent.created_at.toISOString(),
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/api/v1/contents/[username]/[slug]/patch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: null,
body: 'Updated body, even without "create:content:text_root" feature.',
status: 'published',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -198,6 +199,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Valid user trying to update "root" content.',
body: 'It should be possible, even without the "create:content:text_child" feature.',
status: 'published',
type: 'content',
source_url: 'http://www.tabnews.com.br/',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -453,6 +455,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Tentando atualizar o dono do conteúdo.',
body: 'Campo "owner_id" da request deveria ser ignorado e pego através da sessão.',
status: 'published',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -496,6 +499,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body novo',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -541,6 +545,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Title',
body: 'New body',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -641,6 +646,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Começando com caractere proibido no Postgres',
body: 'Terminando com caractere proibido no Postgres',
status: 'draft',
type: 'content',
source_url: 'https://teste-caractere.invalido/',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -760,6 +766,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Espaço só no fim',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -828,6 +835,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -968,6 +976,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Segundo conteúdo',
body: 'Segundo conteúdo',
status: 'published',
type: 'content',
tabcoins: 0,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -1042,6 +1051,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1136,6 +1146,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1178,6 +1189,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título novo',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1339,6 +1351,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: null,
body: 'Child old body',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1381,6 +1394,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título válido, mas com espaços em branco no início e no fim',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1423,6 +1437,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: `Tab & News | Conteúdos com \n valor <strong>concreto</strong> e "massa"> participe! '\\o/'`,
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1465,6 +1480,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1508,6 +1524,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body with relevant texts needs to contain a good amount of words',
status: 'published',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1584,6 +1601,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Title',
body: 'Body with relevant texts needs to contain a good amount of words',
status: 'deleted',
type: 'content',
tabcoins: 1,
tabcoins_credit: 0,
tabcoins_debit: 0,
Expand Down Expand Up @@ -1775,6 +1793,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: 'http://www.tabnews.com.br/',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1817,6 +1836,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: 'https://www.tabnews.com.br/museu',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1859,6 +1879,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Alterar um baita de um Top-Level Domain',
body: 'O maior TLD listado em http://data.iana.org/TLD/tlds-alpha-by-domain.txt possuía 24 caracteres',
status: 'draft',
type: 'content',
source_url: 'https://nic.xn--vermgensberatung-pwb/',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -1901,6 +1922,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Alterar URL bem curta',
body: 'Por exemplo o encurtador do Telegram',
status: 'draft',
type: 'content',
source_url: 'https://t.me',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -2078,6 +2100,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: 'https://www.tabnews.com.br/api/v1/contents?strategy=old',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -2121,6 +2144,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: 'https://www.tabnews.com.br/#:~:text=TabNews,-Status',
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -2190,6 +2214,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Título velho',
body: 'Body velho',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -2281,6 +2306,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Updated title, but not "parent_id"',
body: 'Child content body',
status: 'draft',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down Expand Up @@ -3176,6 +3202,7 @@ describe('PATCH /api/v1/contents/[username]/[slug]', () => {
title: 'Novo title.',
body: 'Novo body.',
status: 'published',
type: 'content',
source_url: null,
created_at: responseBody.created_at,
updated_at: responseBody.updated_at,
Expand Down
Loading

0 comments on commit 3d159a9

Please sign in to comment.