@@ -2,92 +2,136 @@ import supertest from 'supertest'
22
33import Verse from '../../models/verse'
44import app from '../app'
5- import { connect } from '../utils'
5+ import { connect , getUser } from '../utils'
66
77jest . mock ( 'axios' )
88describe ( 'controllers:verse' , ( ) => {
9- let connection
9+ let connection , user
1010
1111 beforeAll ( async ( ) => {
1212 connection = await connect ( )
13+ user = await getUser ( )
1314 } )
1415
1516 afterAll ( async ( ) => {
1617 return connection . disconnect ( )
1718 } )
1819
19- it ( 'should have 31.105 verses' , async done => {
20+ it ( 'should have 837 verses' , async done => {
2021 const count = await Verse . countDocuments ( )
21- expect ( count ) . toEqual ( 31105 )
22+ expect ( count ) . toEqual ( 837 )
2223 done ( )
2324 } )
2425
2526 describe ( 'getChapter' , ( ) => {
26- it ( 'should return object with 6 verses and with the book of Salmos' , async ( ) => {
27- const { body } = await supertest ( app ) . get ( '/verses/nvi/sl/23' )
28- expect ( body . verses . length ) . toBe ( 6 )
29- expect ( body . book . name ) . toBe ( 'Salmos' )
27+ it ( 'should return object with 27 verses and with the book of Tiago (James)' , async ( ) => {
28+ const { body } = await supertest ( app )
29+ . get ( '/verses/nvi/tg/1' )
30+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
31+ expect ( body . verses . length ) . toBe ( 27 )
32+ expect ( body . book . name ) . toBe ( 'Tiago' )
33+ } )
34+
35+ it ( 'should return object with 27 verses and with the book of James (Tiago)' , async ( ) => {
36+ const { body } = await supertest ( app )
37+ . get ( '/verses/nvi/jm/1' )
38+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
39+ expect ( body . verses . length ) . toBe ( 27 )
40+ expect ( body . book . name ) . toBe ( 'Tiago' )
3041 } )
3142
3243 it ( 'should return error 404 and "Book not found" message' , async ( ) => {
33- const { body, statusCode } = await supertest ( app ) . get ( '/verses/nvi/fake/23' )
44+ const { body, statusCode } = await supertest ( app )
45+ . get ( '/verses/nvi/fake/1' )
46+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
3447 expect ( statusCode ) . toBe ( 404 )
3548 expect ( body . msg ) . toBe ( 'Book not found' )
3649 } )
3750
3851 it ( 'should return error 404 and "Chapter not found" message' , async ( ) => {
39- const { body, statusCode } = await supertest ( app ) . get ( '/verses/nvi/sl/160' )
52+ const { body, statusCode } = await supertest ( app )
53+ . get ( '/verses/nvi/tg/10' )
54+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
4055 expect ( statusCode ) . toBe ( 404 )
4156 expect ( body . msg ) . toBe ( 'Chapter not found' )
4257 } )
4358 } )
4459
4560 describe ( 'getVerse' , ( ) => {
4661 it ( 'should return error 404 and "Verse not found" message' , async ( ) => {
47- const { body, statusCode } = await supertest ( app ) . get ( '/verses/nvi/sl/23/50' )
62+ const { body, statusCode } = await supertest ( app )
63+ . get ( '/verses/nvi/tg/1/100' )
64+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
4865 expect ( statusCode ) . toBe ( 404 )
4966 expect ( body . msg ) . toBe ( 'Verse not found' )
5067 } )
5168
5269 it ( 'should return error 404 and "Book not found" message' , async ( ) => {
53- const { body, statusCode } = await supertest ( app ) . get ( '/verses/nvi/fake/23/1' )
70+ const { body, statusCode } = await supertest ( app )
71+ . get ( '/verses/nvi/fake/23/1' )
72+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
5473 expect ( statusCode ) . toBe ( 404 )
5574 expect ( body . msg ) . toBe ( 'Book not found' )
5675 } )
5776
58- it ( 'should return object with text and with the book of Mateus' , async ( ) => {
59- const { body } = await supertest ( app ) . get ( '/verses/nvi/mt/28/19' )
77+ it ( 'should return object with text and with the book of Tiago' , async ( ) => {
78+ const { body } = await supertest ( app )
79+ . get ( '/verses/nvi/tg/1/1' )
80+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
81+ expect ( body . text ) . toBe (
82+ 'Tiago, servo de Deus e do Senhor Jesus Cristo, às doze tribos dispersas entre as nações: Saudações.'
83+ )
84+ expect ( body . book . name ) . toBe ( 'Tiago' )
85+ } )
86+
87+ it ( 'should return object with text and with the book of James' , async ( ) => {
88+ const { body } = await supertest ( app )
89+ . get ( '/verses/nvi/jm/1/1' )
90+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
6091 expect ( body . text ) . toBe (
61- 'Portanto, vão e façam discípulos de todas as nações, batizando-os em nome do Pai e do Filho e do Espírito Santo, '
92+ 'Tiago, servo de Deus e do Senhor Jesus Cristo, às doze tribos dispersas entre as nações: Saudações. '
6293 )
63- expect ( body . book . name ) . toBe ( 'Mateus' )
94+ expect ( body . book . name ) . toBe ( 'Tiago' )
95+ } )
96+ } )
97+
98+ describe ( 'getRandomVerse' , ( ) => {
99+ it ( 'should return object with 1 verse' , async ( ) => {
100+ const { body } = await supertest ( app )
101+ . get ( '/verses/nvi/random' )
102+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
103+ expect ( body . text . length > 0 ) . toBeTruthy ( )
64104 } )
65105 } )
66106
67107 describe ( 'search' , ( ) => {
68108 it ( 'should return error 404 and "Version not found" message' , async ( ) => {
69- const { body, statusCode } = await supertest ( app ) . post ( '/verses/search' ) . send ( { search : 'No princípio' } )
109+ const { body, statusCode } = await supertest ( app ) . post ( '/verses/search' )
110+ . send ( { search : 'No princípio' } )
111+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
70112 expect ( statusCode ) . toBe ( 404 )
71113 expect ( body . msg ) . toBe ( 'Version not found' )
72114 } )
73115
74- it ( 'should return 5 occurences' , async ( ) => {
116+ it ( 'should return 16 occurences' , async ( ) => {
75117 const { body } = await supertest ( app )
76118 . post ( '/verses/search' )
77- . send ( { version : 'nvi' , search : 'No princípio' } )
78- expect ( body . occurrence ) . toBe ( 5 )
119+ . send ( { version : 'nvi' , search : 'luz' } )
120+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
121+ expect ( body . occurrence ) . toBe ( 16 )
79122 expect ( body . verses [ 0 ] . text ) . toBe (
80- 'No princípio Deus criou os céus e a terra .'
123+ 'Então a cobiça, tendo engravidado, dá à luz o pecado; e o pecado, após ter-se consumado, gera a morte .'
81124 )
82125 } )
83126
84- it ( 'should return 5 occurences - deprecated' , async ( ) => {
127+ it ( 'should return 16 occurences - deprecated' , async ( ) => {
85128 const { body } = await supertest ( app )
86129 . post ( '/search' )
87- . send ( { version : 'nvi' , search : 'No princípio' } )
88- expect ( body . occurrence ) . toBe ( 5 )
130+ . send ( { version : 'nvi' , search : 'luz' } )
131+ . set ( 'Authorization' , `Bearer ${ user . token } ` )
132+ expect ( body . occurrence ) . toBe ( 16 )
89133 expect ( body . verses [ 0 ] . text ) . toBe (
90- 'No princípio Deus criou os céus e a terra .'
134+ 'Então a cobiça, tendo engravidado, dá à luz o pecado; e o pecado, após ter-se consumado, gera a morte .'
91135 )
92136 } )
93137
0 commit comments