@@ -7,7 +7,7 @@ const sinon = require('sinon')
7
7
8
8
const { makeMockSocket, removeModuleFromRequireCache } = require ( './utils' )
9
9
10
- describe ( 'realtime#parseNoteIdFromSocket ' , function ( ) {
10
+ describe ( 'realtime#parseNoteIdFromSocketAsync ' , function ( ) {
11
11
let realtime
12
12
13
13
beforeEach ( ( ) => {
@@ -28,13 +28,15 @@ describe('realtime#parseNoteIdFromSocket', function () {
28
28
mock . stopAll ( )
29
29
} )
30
30
31
- it ( 'should return null when socket not send noteId' , function ( ) {
31
+ it ( 'should return null when socket not send noteId' , async function ( ) {
32
32
realtime = require ( '../../lib/realtime' )
33
33
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
+ }
38
40
} )
39
41
40
42
describe ( 'noteId exists' , function ( ) {
@@ -47,17 +49,20 @@ describe('realtime#parseNoteIdFromSocket', function () {
47
49
}
48
50
} )
49
51
} )
50
- it ( 'should return noteId when noteId exists' , function ( ) {
52
+ it ( 'should return noteId when noteId exists' , async function ( ) {
51
53
realtime = require ( '../../lib/realtime' )
52
54
const noteId = '123456'
53
55
const mockSocket = makeMockSocket ( undefined , {
54
56
noteId : noteId
55
57
} )
56
58
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 )
61
66
} )
62
67
} )
63
68
@@ -71,17 +76,15 @@ describe('realtime#parseNoteIdFromSocket', function () {
71
76
}
72
77
} )
73
78
} )
74
- it ( 'should return null when noteId not exists' , function ( ) {
79
+ it ( 'should return null when noteId not exists' , async function ( ) {
75
80
realtime = require ( '../../lib/realtime' )
76
81
const noteId = '123456'
77
82
const mockSocket = makeMockSocket ( undefined , {
78
83
noteId : noteId
79
84
} )
80
85
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 )
85
88
} )
86
89
} )
87
90
@@ -96,17 +99,18 @@ describe('realtime#parseNoteIdFromSocket', function () {
96
99
}
97
100
} )
98
101
} )
99
- it ( 'should return error when noteId parse error' , function ( ) {
102
+ it ( 'should return error when noteId parse error' , async function ( ) {
100
103
realtime = require ( '../../lib/realtime' )
101
104
const noteId = '123456'
102
105
const mockSocket = makeMockSocket ( undefined , {
103
106
noteId : noteId
104
107
} )
105
108
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
+ }
110
114
} )
111
115
} )
112
116
} )
0 commit comments