Skip to content

Commit 9c8a38f

Browse files
test: update tests
1 parent 02d708e commit 9c8a38f

6 files changed

Lines changed: 41 additions & 27 deletions

File tree

test/comments.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ describe('Comments', () => {
2929
.to.equal('The video identified by the <code><a href="/youtube/v3/docs/commentThreads/list#videoId">videoId</a></code> parameter has disabled comments.')
3030
})
3131

32-
it('should not work with invalid videos', async () => {
33-
expect(await youtube.getVideoComments('JSFSFDKFaVeryFakeVideoID').catch(error => error.message))
34-
.to.equal('The video identified by the <code><a href="/youtube/v3/docs/commentThreads/list#videoId">videoId</a></code> parameter could not be found.')
32+
it('should work when searching comments by video title', async () => {
33+
const comments = await youtube.getVideoComments('never gonna give you up')
34+
35+
expect(comments.items).to.be.an.instanceOf(Array)
36+
expect(comments.items[0]).to.be.an.instanceOf(Comment)
37+
expect(comments.nextPageToken).to.be.a('string')
3538
})
3639

3740
it('should return an array with a length of <= maxPerPage', async () => {

test/playlist-items.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ if (!apiKey) {
1212
let playlist: Playlist
1313

1414
describe('Playlist items', () => {
15-
it('should reject if the playlist isn\'t found', async () => {
15+
it('should reject if the playlist ID is invalid', async () => {
1616
expect(await youtube.getPlaylistItems('DSFDKLSDFaVeryFakePlaylistID')
17-
.catch(error => error.message)).to.equal('The playlist identified with the request\'s <code>playlistId</code> parameter cannot be found.')
17+
.catch(error => error.message)).to.equal('Invalid Value')
1818
})
1919

2020
it('should reject if maxPerPage is > 50', async () => {

test/request.spec.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!apiKey) {
1212
}
1313

1414
const request = new Request('https://www.googleapis.com/youtube/v3/', { apiKey })
15-
const testRequest = new Request('https://apichallenges.herokuapp.com/mirror/request/')
15+
const testRequest = new Request('https://httpbin.org/anything')
1616

1717
describe('Requests', () => {
1818
it('should work consistently', async () => {
@@ -33,22 +33,31 @@ describe('Requests', () => {
3333

3434
it('should work with multipart requests', async () => {
3535
const testData = JSON.stringify({ testKey: 'testValue' })
36-
const result: string = await testRequest.multipartStreamPost('', {
36+
const result: {
37+
args: any
38+
data: string
39+
files: any
40+
form: { [key: number]: string }
41+
headers: { [key: string]: string }
42+
json: any
43+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
44+
origin: string
45+
url: string
46+
} = await testRequest.multipartStreamPost('', {
3747
parts: [{
3848
data: testData
3949
}, {
4050
data: readFileSync(path.join(process.cwd(), 'package.json'))
4151
}],
4252
accept: 'application/json'
43-
}).then(result => result.messageDetails)
44-
45-
expect(result.startsWith('POST https://apichallenges.herokuapp.com/mirror/request/')).to.equal(true)
46-
expect(result).to.include('Content-Type: multipart/form-data; boundary=--------------------------')
47-
expect(result).to.include(`Content-Disposition: form-data; name="0"\nContent-Type: application/json\n\n${testData}`)
48-
expect(result).to.include(`Content-Disposition: form-data; name="1"\nContent-Type: application/octet-stream\n\n${
49-
readFileSync(path.join(process.cwd(), 'package.json'), { encoding: 'utf8' })
50-
}`)
51-
expect(result.endsWith('--\n')).to.equal(true)
53+
})
54+
55+
expect(result.url).to.equal('https://httpbin.org/anything')
56+
expect(result.method).to.equal('POST')
57+
expect(result.url).to.equal('https://httpbin.org/anything')
58+
expect(result.headers['Content-Type']).to.include('multipart/form-data; boundary=--------------------------')
59+
expect(JSON.stringify(result.form[0])).to.equal(JSON.stringify(testData))
60+
expect(result.form[1]).to.equal(readFileSync(path.join(process.cwd(), 'package.json'), { encoding: 'utf8' }))
5261
})
5362

5463
it('should throw errors', async () => {

test/search.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Searching', () => {
5555
it('should set what it can with search results', async () => {
5656
const channel = defaultChannelsSearch.items[0]
5757

58-
expect(channel.id).to.equal('UCuAXFkgsw1L7xaCfnd5JJOw')
58+
expect(channel.id).to.equal('UCwZEU0wAwIyZb4x5G_KJp2w')
5959
expect(channel.country).to.equal(undefined)
6060
expect(channel.language).to.equal(undefined)
6161
expect(channel.views).to.equal(undefined)

test/subscription.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ describe('Subscriptions', () => {
1717

1818
expect(testSubscription.id).to.be.a('string')
1919
expect(testSubscription.subscriber.id).to.equal(subscriber?.id)
20-
expect(testSubscription.activities).to.satisfy(a => a === 'all' || a === 'uploads')
21-
expect(testSubscription.channel).to.satisfy(c => typeof c.id === 'string' && typeof c.name === 'string')
20+
expect(testSubscription.activities).to.satisfy((a: typeof Subscription.prototype.activities) => a === 'all' || a === 'uploads')
21+
expect(testSubscription.channel).to.satisfy((c: typeof Subscription.prototype.channel) => typeof c.id === 'string' && typeof c.name === 'string')
2222
expect(testSubscription.dateSubscribed).to.be.an.instanceOf(Date)
2323
expect(testSubscription.description).to.be.a('string')
2424
expect(testSubscription.full).to.equal(true)
25-
expect(testSubscription.items).to.satisfy(i => typeof i.new === 'number' && typeof i.total === 'number')
26-
expect(testSubscription.subscriber)
27-
.to.satisfy(s => typeof s.id === 'string' && typeof s.name === 'string' && typeof s.description === 'string' && typeof s.thumbnails === 'object')
28-
expect(testSubscription.thumbnails).to.satisfy(t => typeof t.default === 'object' && typeof t.medium === 'object' && typeof t.high === 'object')
25+
expect(testSubscription.items).to.satisfy((i: typeof Subscription.prototype.items) => typeof i.new === 'number' && typeof i.total === 'number')
26+
27+
expect(testSubscription.subscriber).to.satisfy((s: typeof Subscription.prototype.subscriber) =>
28+
typeof s.id === 'string' && typeof s.name === 'string' && typeof s.description === 'string' && typeof s.thumbnails === 'object')
29+
expect(testSubscription.thumbnails).to.satisfy((t: typeof Subscription.prototype.thumbnails) =>
30+
typeof t.default === 'object' && typeof t.medium === 'object' && typeof t.high === 'object')
2931
expect(testSubscription.title).to.be.a('string')
3032
})
3133

@@ -34,7 +36,7 @@ describe('Subscriptions', () => {
3436

3537
try {
3638
new Subscription(youtube, { kind: 'invalid' })
37-
} catch (err) {
39+
} catch (err: any) {
3840
error = err.message
3941
}
4042

test/youtube.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Request } from '../src/util'
33
import YouTube from '../src'
44
import { expect } from 'chai'
55

6-
const testRequest = new Request('https://apichallenges.herokuapp.com/mirror/request/')
6+
const testRequest = new Request('https://httpbin.org/anything')
77

88
describe('YouTube instance', () => {
99
it('should set authorization', async () => {
@@ -15,14 +15,14 @@ describe('YouTube instance', () => {
1515
accept: 'application/json'
1616
})
1717

18-
expect(response.messageDetails.includes('Authorization: Bearer Another API key\n'))
18+
expect(response.headers['Authorization']).to.equal('Bearer Another API key')
1919

2020
youtube.setAuthorization({ apiKey: 'Fakest API Key Ever' })
2121
response = await youtube._request.get('', {
2222
authorizationOptions: { apiKey: true },
2323
accept: 'application/json'
2424
})
2525

26-
expect(response.messageDetails.includes('key: Fakest API Key Ever\n'))
26+
expect(response.args['key']).to.equal('Fakest API Key Ever')
2727
})
2828
})

0 commit comments

Comments
 (0)