11'use strict' ;
22
3- const { app } = require ( 'egg-mock/bootstrap' ) ;
3+ const { app, assert } = require ( 'egg-mock/bootstrap' ) ;
44
55describe ( 'test/app/controller/sign.test.js' , ( ) => {
6+ const loginname = 'loginname' + Date . now ( ) ;
7+ const email = `${ loginname } @email.com` ;
8+
69 it ( 'should GET /signup' , async ( ) => {
710 await app . httpRequest ( )
811 . get ( '/signup' )
@@ -27,4 +30,129 @@ describe('test/app/controller/sign.test.js', () => {
2730 . expect ( 302 ) ;
2831 } ) ;
2932
33+ it ( 'should GET /search_pass' , async ( ) => {
34+ const res = await app . httpRequest ( )
35+ . get ( '/search_pass' ) ;
36+ assert ( res . statusCode === 200 ) ;
37+ } ) ;
38+
39+ it ( 'should GET /reset_pass' , async ( ) => {
40+ const res = await app . httpRequest ( )
41+ . get ( '/reset_pass' ) ;
42+ assert ( res . statusCode === 403 ) ;
43+ assert ( res . text . includes ( '信息有误,密码无法重置。' ) ) ;
44+ } ) ;
45+
46+ it ( 'should GET /active_account' , async ( ) => {
47+ const res = await app . httpRequest ( )
48+ . get ( '/active_account' ) ;
49+ assert ( res . text . includes ( '用户不存在' ) ) ;
50+ } ) ;
51+
52+ it ( 'should POST /signup' , async ( ) => {
53+ app . mockCsrf ( ) ;
54+ const res = await app . httpRequest ( )
55+ . post ( '/signup' )
56+ . type ( 'form' )
57+ . send ( { } ) ;
58+
59+ assert ( res . statusCode === 422 ) ;
60+ assert ( res . text . includes ( '信息不完整。' ) ) ;
61+ } ) ;
62+
63+ it ( 'should POST /signup loginname less 5' , async ( ) => {
64+ app . mockCsrf ( ) ;
65+ const res = await app . httpRequest ( )
66+ . post ( '/signup' )
67+ . type ( 'form' )
68+ . send ( {
69+ loginname : 'logi' ,
70+ 71+ pass : '123456' ,
72+ re_pass : '123456' ,
73+ } ) ;
74+
75+ assert ( res . statusCode === 422 ) ;
76+ assert ( res . text . includes ( '用户名至少需要5个字符。' ) ) ;
77+ } ) ;
78+
79+ it ( 'should POST /signup invalid loginname' , async ( ) => {
80+ app . mockCsrf ( ) ;
81+ const res = await app . httpRequest ( )
82+ . post ( '/signup' )
83+ . type ( 'form' )
84+ . send ( {
85+ loginname : 'login@name' ,
86+ 87+ pass : '123456' ,
88+ re_pass : '123456' ,
89+ } ) ;
90+
91+ assert ( res . statusCode === 422 ) ;
92+ assert ( res . text . includes ( '用户名不合法。' ) ) ;
93+ } ) ;
94+
95+ it ( 'should POST /signup invalid email' , async ( ) => {
96+ app . mockCsrf ( ) ;
97+ const res = await app . httpRequest ( )
98+ . post ( '/signup' )
99+ . type ( 'form' )
100+ . send ( {
101+ loginname : 'loginname' ,
102+ email : 'invalid_email' ,
103+ pass : '123456' ,
104+ re_pass : '123456' ,
105+ } ) ;
106+
107+ assert ( res . statusCode === 422 ) ;
108+ assert ( res . text . includes ( '邮箱不合法。' ) ) ;
109+ } ) ;
110+
111+ it ( 'should POST /signup unmatch password' , async ( ) => {
112+ app . mockCsrf ( ) ;
113+ const res = await app . httpRequest ( )
114+ . post ( '/signup' )
115+ . type ( 'form' )
116+ . send ( {
117+ loginname : 'loginname' ,
118+ 119+ pass : '123456' ,
120+ re_pass : '1234567' ,
121+ } ) ;
122+
123+ assert ( res . statusCode === 422 ) ;
124+ assert ( res . text . includes ( '两次密码输入不一致。' ) ) ;
125+ } ) ;
126+
127+ it ( 'should POST /signup ok' , async ( ) => {
128+ app . mockCsrf ( ) ;
129+ const res = await app . httpRequest ( )
130+ . post ( '/signup' )
131+ . type ( 'form' )
132+ . send ( {
133+ loginname,
134+ email,
135+ pass : '123456' ,
136+ re_pass : '123456' ,
137+ } ) ;
138+
139+ assert ( res . statusCode === 200 ) ;
140+ assert ( res . text . includes ( '欢迎加入 cnode!我们已给您的注册邮箱发送了一封邮件,请点击里面的链接来激活您的帐号' ) ) ;
141+ } ) ;
142+
143+ it ( 'should POST /signup user or email in use' , async ( ) => {
144+ app . mockCsrf ( ) ;
145+ const res = await app . httpRequest ( )
146+ . post ( '/signup' )
147+ . type ( 'form' )
148+ . send ( {
149+ loginname,
150+ email,
151+ pass : '123456' ,
152+ re_pass : '123456' ,
153+ } ) ;
154+
155+ assert ( res . statusCode === 422 ) ;
156+ assert ( res . text . includes ( '用户名或邮箱已被使用。' ) ) ;
157+ } ) ;
30158} ) ;
0 commit comments