-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
155 lines (145 loc) · 5.19 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
var alexa = require('./index');
var should = require('should');
describe('Amazon Echo NodeJS ToolKit', function () {
describe('Echo Launch Request', function () {
it('should successfully construct a valid launch response', function (done) {
var req = {
body: {
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
"attributes": {},
"user": {
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
}
},
"request": {
"type": "LaunchRequest",
"requestId": "amzn1.echo-api.request.9cdaa4db-f20e-4c58-8d01-c75322d6c423"
}
}
};
alexa.launchRequest(req.body);
// Testing..
alexa.sessionId.should.be.exactly(req.body.session.sessionId);
alexa.userId.should.be.exactly(req.body.session.user.userId);
alexa.types.should.be.exactly('LAUNCH_REQUEST');
alexa.response('Launch Response', {
title: 'Launch Card Title',
subtitle: 'Launch Card Subtitle',
content: 'Launch Card Content'
}, false, function (error, res) {
if(error) {
return done(error);
}
// Testing..
res.version.should.be.exactly(req.body.version);
res.sessionAttributes.should.eql(req.body.session.attributes);
res.response.outputSpeech.text.should.be.exactly('Launch Response');
res.response.shouldEndSession.should.be.false;
done();
});
});
});
describe('Echo Intent Request', function () {
it('should successfully construct a valid intent response', function (done) {
var req = {
body: {
"version": "1.0",
"session": {
"new": false,
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
"attributes": {
"supportedHoroscopePeriods": {
"daily": true,
"weekly": false,
"monthly": false
}
},
"user": {
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
}
},
"request": {
"type": "IntentRequest",
"requestId": " amzn1.echo-api.request.6919844a-733e-4e89-893a-fdcb77e2ef0d",
"intent": {
"name": "GetZodiacHoroscopeIntent",
"slots": {
"ZodiacSign": {
"name": "ZodiacSign",
"value": "virgo"
}
}
}
}
}
};
alexa.intentRequest(req.body);
// Testing..
alexa.sessionId.should.be.exactly(req.body.session.sessionId);
alexa.userId.should.be.exactly(req.body.session.user.userId);
alexa.intentName.should.be.exactly(req.body.request.intent.name);
alexa.slots.should.eql(req.body.request.intent.slots);
alexa.types.should.be.exactly('INTENT_REQUEST');
alexa.response('Intent Response', {
title: 'Intent Card Title',
subtitle: 'Intent Card Subtitle',
content: 'Intent Card Content'
}, true, function (error, res) {
if(error) {
return done(error);
}
// Testing..
res.version.should.be.exactly(req.body.version);
res.sessionAttributes.should.eql(req.body.session.attributes);
res.response.outputSpeech.text.should.be.exactly('Intent Response');
res.response.shouldEndSession.should.be.true;
done();
});
});
});
describe('Echo Session Ended Request', function () {
it('should successfully construct a valid session ended response', function (done) {
var req = {
body: {
"version": "1.0",
"session": {
"new": false,
"sessionId": "amzn1.echo-api.session.abeee1a7-aee0-41e6-8192-e6faaed9f5ef",
"attributes": {
"supportedHoroscopePeriods": {
"daily": true,
"weekly": false,
"monthly": false
}
},
"user": {
"userId": "amzn1.account.AM3B227HF3FAM1B261HK7FFM3A2"
}
},
"request": {
"type": "SessionEndedRequest",
"requestId": "amzn1.echo-api.request.d8c37cd6-0e1c-458e-8877-5bb4160bf1e1",
"reason": "USER_INITIATED"
}
}
};
alexa.sessionEndedRequest(req.body);
// Testing..
alexa.sessionId.should.be.exactly(req.body.session.sessionId);
alexa.userId.should.be.exactly(req.body.session.user.userId);
alexa.types.should.be.exactly('SESSION_ENDED_REQUEST');
alexa.response(function (error, res) {
if(error) {
return done(error);
}
// Testing..
res.version.should.be.exactly(req.body.version);
done();
});
});
});
});