@@ -14,62 +14,105 @@ describe("SigninResponse", function() {
1414 let subject = new SigninResponse ( "state=foo" ) ;
1515 subject . state . should . equal ( "foo" ) ;
1616 } ) ;
17-
17+
1818 it ( "should return SigninResponse if no error" , function ( ) {
1919 let subject = new SigninResponse ( "" ) ;
2020 subject . should . be . instanceof ( SigninResponse ) ;
2121 } ) ;
22-
22+
2323 it ( "should return ErrorResponse if error" , function ( ) {
2424 let subject = new SigninResponse ( "error=foo" ) ;
2525 subject . should . be . instanceof ( ErrorResponse ) ;
2626 } ) ;
27-
27+
2828 it ( "should read id_token" , function ( ) {
2929 let subject = new SigninResponse ( "id_token=foo" ) ;
3030 subject . id_token . should . equal ( "foo" ) ;
3131 } ) ;
32-
32+
3333 it ( "should read session_state" , function ( ) {
3434 let subject = new SigninResponse ( "session_state=foo" ) ;
3535 subject . session_state . should . equal ( "foo" ) ;
3636 } ) ;
37-
37+
3838 it ( "should read access_token" , function ( ) {
3939 let subject = new SigninResponse ( "access_token=foo" ) ;
4040 subject . access_token . should . equal ( "foo" ) ;
4141 } ) ;
42-
42+
4343 it ( "should read token_type" , function ( ) {
4444 let subject = new SigninResponse ( "token_type=foo" ) ;
4545 subject . token_type . should . equal ( "foo" ) ;
4646 } ) ;
47-
47+
4848 it ( "should read scope" , function ( ) {
4949 let subject = new SigninResponse ( "scope=foo" ) ;
5050 subject . scope . should . equal ( "foo" ) ;
5151 } ) ;
52-
52+
5353 it ( "should read expires_in" , function ( ) {
5454 let subject = new SigninResponse ( "expires_in=10" ) ;
5555 subject . expires_in . should . equal ( 10 ) ;
5656 } ) ;
57-
57+
5858 it ( "should calculate expires_at" , function ( ) {
5959 let subject = new SigninResponse ( "expires_in=10" ) ;
60- subject . expires_at . should . equal ( parseInt ( ( Date . now ( ) / 1000 ) + 10 ) ) ;
60+ subject . expires_at . should . equal ( parseInt ( ( Date . now ( ) / 1000 ) + 10 ) ) ;
6161 } ) ;
62-
62+
6363 it ( "should not read invalid expires_in" , function ( ) {
6464 let subject = new SigninResponse ( "expires_in=foo" ) ;
6565 expect ( subject . expires_in ) . to . be . undefined ;
6666 expect ( subject . expires_at ) . to . be . undefined ;
67-
67+
6868 subject = new SigninResponse ( "expires_in=-10" ) ;
6969 expect ( subject . expires_in ) . to . be . undefined ;
7070 expect ( subject . expires_at ) . to . be . undefined ;
7171 } ) ;
7272
7373 } ) ;
7474
75+ describe ( "scopes" , function ( ) {
76+ it ( "should return list of scope" , function ( ) {
77+ let subject = new SigninResponse ( "scope=foo" ) ;
78+ subject . scopes . should . deep . equal ( [ "foo" ] ) ;
79+
80+ subject = new SigninResponse ( "scope=foo%20bar" ) ;
81+ subject . scopes . should . deep . equal ( [ "foo" , "bar" ] ) ;
82+
83+ subject = new SigninResponse ( "scope=foo%20bar%20baz" ) ;
84+ subject . scopes . should . deep . equal ( [ "foo" , "bar" , "baz" ] ) ;
85+ } ) ;
86+ } ) ;
87+
88+ describe ( "expires_in" , function ( ) {
89+ it ( "should calculate how much time left" , function ( ) {
90+ Date . now = function ( ) {
91+ return 1000 * 1000 ; // ms
92+ }
93+ let subject = new SigninResponse ( "expires_in=100" ) ;
94+ subject . expires_in . should . equal ( 100 ) ;
95+
96+ Date . now = function ( ) {
97+ return 1050 * 1000 ;
98+ }
99+ subject . expires_in . should . equal ( 50 ) ;
100+ } ) ;
101+ } ) ;
102+
103+ describe ( "expired" , function ( ) {
104+ it ( "should calculate how much time left" , function ( ) {
105+ Date . now = function ( ) {
106+ return 1000 * 1000 ; // ms
107+ }
108+ let subject = new SigninResponse ( "expires_in=100" ) ;
109+ subject . expired . should . be . false ;
110+
111+ Date . now = function ( ) {
112+ return 1100 * 1000 ; // ms
113+ }
114+ subject . expired . should . be . true ;
115+ } ) ;
116+ } ) ;
117+
75118} ) ;
0 commit comments