hubot-nextbus 2.2.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,215 +0,0 @@
1
- /* eslint-disable func-names */
2
- /* global describe beforeEach afterEach context it */
3
-
4
- const Helper = require('hubot-test-helper');
5
- const chai = require('chai');
6
- const nock = require('nock');
7
-
8
- const {
9
- expect,
10
- } = chai;
11
-
12
- const helper = new Helper('../src/nextbus.js');
13
-
14
- // Alter time as test runs
15
- const originalDateNow = Date.now;
16
-
17
- describe('hubot-nextbus', () => {
18
- beforeEach(() => {
19
- nock.disableNetConnect();
20
- nock('https://gtfs.transitnownash.org')
21
- .get('/stops/near/36.1650,-86.78404/1000.json?per_page=5')
22
- .replyWithFile(200, `${__dirname}/fixtures/stops-near-gps.json`);
23
- nock('https://gtfs.transitnownash.org')
24
- .get('/agencies.json')
25
- .replyWithFile(200, `${__dirname}/fixtures/agencies.json`);
26
- nock('https://gtfs.transitnownash.org')
27
- .get('/stops/CHA7AWN/trips.json?per_page=2000')
28
- .replyWithFile(200, `${__dirname}/fixtures/stops-CHA7AWN-trips.json`);
29
- });
30
-
31
- afterEach(() => {
32
- nock.cleanAll();
33
- Date.now = originalDateNow;
34
- });
35
-
36
- context('regular tests with latitude/longitude set', () => {
37
- beforeEach(function () {
38
- Date.now = () => Date.parse('Fri, 1 Oct 2021 12:00:00 UTC');
39
- process.env.HUBOT_NEXTBUS_LAT_LON = '36.1650,-86.78404';
40
- this.room = helper.createRoom();
41
- });
42
-
43
- afterEach(function () {
44
- this.room.destroy();
45
- delete process.env.HUBOT_NEXTBUS_LAT_LON;
46
- });
47
-
48
- // hubot nextbus
49
- it('returns the next bus for closest stop', function (done) {
50
- const selfRoom = this.room;
51
- selfRoom.user.say('alice', '@hubot nextbus');
52
- setTimeout(
53
- () => {
54
- try {
55
- expect(selfRoom.messages).to.eql([
56
- ['alice', '@hubot nextbus'],
57
- ['hubot', 'Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB'],
58
- [
59
- 'hubot',
60
- ' 7:01 AM #50 - CHARLOTTE WALMART in a minute \n'
61
- + ' 7:15 AM #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes \n'
62
- + ' 7:16 AM #50 - CHARLOTTE WALMART in 16 minutes \n'
63
- + ' 7:31 AM #50 - CHARLOTTE WALMART in 31 minutes \n'
64
- + ' 7:35 AM #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes ',
65
- ],
66
- ]);
67
- done();
68
- } catch (err) {
69
- done(err);
70
- }
71
- },
72
- 100,
73
- );
74
- });
75
-
76
- // hubot nextbus stop <id>
77
- it('returns the next bus for a particular stop', function (done) {
78
- const selfRoom = this.room;
79
- selfRoom.user.say('alice', '@hubot nextbus stop CHA7AWN');
80
- setTimeout(
81
- () => {
82
- try {
83
- expect(selfRoom.messages).to.eql([
84
- ['alice', '@hubot nextbus stop CHA7AWN'],
85
- ['hubot', 'Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB'],
86
- [
87
- 'hubot',
88
- ' 7:01 AM #50 - CHARLOTTE WALMART in a minute \n'
89
- + ' 7:15 AM #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes \n'
90
- + ' 7:16 AM #50 - CHARLOTTE WALMART in 16 minutes \n'
91
- + ' 7:31 AM #50 - CHARLOTTE WALMART in 31 minutes \n'
92
- + ' 7:35 AM #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes ',
93
- ],
94
- ]);
95
- done();
96
- } catch (err) {
97
- done(err);
98
- }
99
- },
100
- 100,
101
- );
102
- });
103
-
104
- // hubot nextbus stops
105
- it('returns the list of nearby stops', function (done) {
106
- const selfRoom = this.room;
107
- selfRoom.user.say('alice', '@hubot nextbus stops');
108
- setTimeout(
109
- () => {
110
- try {
111
- expect(selfRoom.messages).to.eql([
112
- ['alice', '@hubot nextbus stops'],
113
- ['hubot', 'List of nearby stops:'],
114
- [
115
- 'hubot',
116
- '- [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB\n'
117
- + '- [CHA7AEN] CHARLOTTE AVE & 7TH AVE N EB\n'
118
- + '- [6AVDEASN] 6TH AVE & DEADERICK ST SB\n'
119
- + '- [6AVDEANN] 6TH AVE N & DEADERICK ST NB\n'
120
- + '- [UNI7AWN] UNION ST & 7TH AVE N WB',
121
- ],
122
- ]);
123
- done();
124
- } catch (err) {
125
- done(err);
126
- }
127
- },
128
- 100,
129
- );
130
- });
131
- });
132
-
133
- context('regular tests with default stop ID set', () => {
134
- beforeEach(function () {
135
- Date.now = () => Date.parse('Fri, 1 Oct 2021 12:00:00 UTC');
136
- process.env.HUBOT_NEXTBUS_LAT_LON = '0,0';
137
- process.env.HUBOT_NEXTBUS_STOP_ID = 'CHA7AWN';
138
- this.room = helper.createRoom();
139
- });
140
-
141
- afterEach(function () {
142
- this.room.destroy();
143
- delete process.env.HUBOT_NEXTBUS_LAT_LON;
144
- delete process.env.HUBOT_NEXTBUS_STOP_ID;
145
- });
146
-
147
- // hubot nextbus
148
- it('returns the next bus for closest stop', function (done) {
149
- const selfRoom = this.room;
150
- selfRoom.user.say('alice', '@hubot nextbus');
151
- setTimeout(
152
- () => {
153
- try {
154
- expect(selfRoom.messages).to.eql([
155
- ['alice', '@hubot nextbus'],
156
- ['hubot', 'Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB'],
157
- [
158
- 'hubot',
159
- ' 7:01 AM #50 - CHARLOTTE WALMART in a minute \n'
160
- + ' 7:15 AM #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes \n'
161
- + ' 7:16 AM #50 - CHARLOTTE WALMART in 16 minutes \n'
162
- + ' 7:31 AM #50 - CHARLOTTE WALMART in 31 minutes \n'
163
- + ' 7:35 AM #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes ',
164
- ],
165
- ]);
166
- done();
167
- } catch (err) {
168
- done(err);
169
- }
170
- },
171
- 100,
172
- );
173
- });
174
- });
175
-
176
- context('time spans days', () => {
177
- beforeEach(function () {
178
- Date.now = () => Date.parse('Fri, 1 Oct 2021 04:00:00 UTC');
179
- process.env.HUBOT_NEXTBUS_LAT_LON = '36.1650,-86.78404';
180
- this.room = helper.createRoom();
181
- });
182
-
183
- afterEach(function () {
184
- this.room.destroy();
185
- delete process.env.HUBOT_NEXTBUS_LAT_LON;
186
- });
187
-
188
- // hubot nextbus
189
- it('returns the next bus for closest stop', function (done) {
190
- const selfRoom = this.room;
191
- selfRoom.user.say('alice', '@hubot nextbus');
192
- setTimeout(
193
- () => {
194
- try {
195
- expect(selfRoom.messages).to.eql([
196
- ['alice', '@hubot nextbus'],
197
- ['hubot', 'Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB'],
198
- [
199
- 'hubot',
200
- ' 11:16 PM #50 - CHARLOTTE WALMART in 16 minutes \n'
201
- + ' 11:15 PM #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes \n'
202
- + ' 11:46 PM #50 - CHARLOTTE WALMART in an hour \n'
203
- + ' 12:16 AM #50 - CHARLOTTE WALMART in an hour ',
204
- ],
205
- ]);
206
- done();
207
- } catch (err) {
208
- done(err);
209
- }
210
- },
211
- 100,
212
- );
213
- });
214
- });
215
- });