@@ -7,7 +7,7 @@ const sinon = require('sinon')
77
88const { makeMockSocket, removeModuleFromRequireCache } = require ( './utils' )
99
10- describe ( 'realtime#parseNoteIdFromSocket ' , function ( ) {
10+ describe ( 'realtime#parseNoteIdFromSocketAsync ' , function ( ) {
1111 let realtime
1212
1313 beforeEach ( ( ) => {
@@ -28,13 +28,15 @@ describe('realtime#parseNoteIdFromSocket', function () {
2828 mock . stopAll ( )
2929 } )
3030
31- it ( 'should return null when socket not send noteId' , function ( ) {
31+ it ( 'should return null when socket not send noteId' , async function ( ) {
3232 realtime = require ( '../../lib/realtime' )
3333 const mockSocket = makeMockSocket ( )
34- const fakeCallback = sinon . fake ( )
35- realtime . parseNoteIdFromSocket ( mockSocket , fakeCallback )
36- assert ( fakeCallback . called )
37- assert . deepStrictEqual ( fakeCallback . getCall ( 0 ) . args , [ null , null ] )
34+ try {
35+ const notes = await realtime . parseNoteIdFromSocketAsync ( mockSocket )
36+ assert ( notes === null )
37+ } catch ( err ) {
38+ assert . fail ( 'should not occur any error' )
39+ }
3840 } )
3941
4042 describe ( 'noteId exists' , function ( ) {
@@ -47,17 +49,20 @@ describe('realtime#parseNoteIdFromSocket', function () {
4749 }
4850 } )
4951 } )
50- it ( 'should return noteId when noteId exists' , function ( ) {
52+ it ( 'should return noteId when noteId exists' , async function ( ) {
5153 realtime = require ( '../../lib/realtime' )
5254 const noteId = '123456'
5355 const mockSocket = makeMockSocket ( undefined , {
5456 noteId : noteId
5557 } )
5658 realtime = require ( '../../lib/realtime' )
57- const fakeCallback = sinon . fake ( )
58- realtime . parseNoteIdFromSocket ( mockSocket , fakeCallback )
59- assert ( fakeCallback . called )
60- assert . deepStrictEqual ( fakeCallback . getCall ( 0 ) . args , [ null , noteId ] )
59+ let parsedNoteId
60+ try {
61+ parsedNoteId = await realtime . parseNoteIdFromSocketAsync ( mockSocket )
62+ } catch ( err ) {
63+ assert . fail ( `should not occur any error ${ err } ` )
64+ }
65+ assert ( parsedNoteId === noteId )
6166 } )
6267 } )
6368
@@ -71,17 +76,15 @@ describe('realtime#parseNoteIdFromSocket', function () {
7176 }
7277 } )
7378 } )
74- it ( 'should return null when noteId not exists' , function ( ) {
79+ it ( 'should return null when noteId not exists' , async function ( ) {
7580 realtime = require ( '../../lib/realtime' )
7681 const noteId = '123456'
7782 const mockSocket = makeMockSocket ( undefined , {
7883 noteId : noteId
7984 } )
8085 realtime = require ( '../../lib/realtime' )
81- const fakeCallback = sinon . fake ( )
82- realtime . parseNoteIdFromSocket ( mockSocket , fakeCallback )
83- assert ( fakeCallback . called )
84- assert . deepStrictEqual ( fakeCallback . getCall ( 0 ) . args , [ null , null ] )
86+ const parsedNoteId = await realtime . parseNoteIdFromSocketAsync ( mockSocket )
87+ assert ( parsedNoteId === null )
8588 } )
8689 } )
8790
@@ -96,17 +99,18 @@ describe('realtime#parseNoteIdFromSocket', function () {
9699 }
97100 } )
98101 } )
99- it ( 'should return error when noteId parse error' , function ( ) {
102+ it ( 'should return error when noteId parse error' , async function ( ) {
100103 realtime = require ( '../../lib/realtime' )
101104 const noteId = '123456'
102105 const mockSocket = makeMockSocket ( undefined , {
103106 noteId : noteId
104107 } )
105108 realtime = require ( '../../lib/realtime' )
106- const fakeCallback = sinon . fake ( )
107- realtime . parseNoteIdFromSocket ( mockSocket , fakeCallback )
108- assert ( fakeCallback . called )
109- assert . deepStrictEqual ( fakeCallback . getCall ( 0 ) . args , [ 'error' , null ] )
109+ try {
110+ await realtime . parseNoteIdFromSocketAsync ( mockSocket )
111+ } catch ( err ) {
112+ assert ( err === 'error' )
113+ }
110114 } )
111115 } )
112116} )
0 commit comments