Skip to content
Permalink
Browse files
Add tests for authenticateUserByName
  • Loading branch information
thornbill committed May 28, 2020
1 parent de9aed2 commit d3a565c217f6ab01b421a9224342dca49ea1d232
Showing with 63 additions and 13 deletions.
  1. +1 −0 jest.config.js
  2. +2 −0 jest.setup.js
  3. +1 −0 package.json
  4. +29 −11 tests/apiClient.test.js
  5. +30 −2 yarn.lock
@@ -9,4 +9,5 @@ module.exports = {
'^.+\\.ts?$': 'ts-jest',
'^.+\\.js?$': 'ts-jest'
},
setupFiles: ['./jest.setup.js']
};
@@ -0,0 +1,2 @@
// Add fetch polyfill for jest
import 'isomorphic-fetch';
@@ -16,6 +16,7 @@
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.9.0",
"eslint-plugin-promise": "^4.2.1",
"isomorphic-fetch": "^2.2.1",
"jest": "^26.0.1",
"jest-junit": "^10.0.0",
"jsdoc": "^3.6.4",
@@ -4,7 +4,7 @@ let client;

beforeEach(() => {
client = new apiClient(
'http://demo.jellyfin.org/stable',
'https://demo.jellyfin.org/stable',
'Jellyfin Web',
'10.5.0',
'Firefox',
@@ -18,7 +18,7 @@ describe('ApiClient class', () => {
});

it('has the expected constructor', () => {
expect(client._serverAddress).toBe('http://demo.jellyfin.org/stable');
expect(client._serverAddress).toBe('https://demo.jellyfin.org/stable');
expect(client._appName).toBe('Jellyfin Web');
expect(client._appVersion).toBe('10.5.0');
expect(client._deviceName).toBe('Firefox');
@@ -28,7 +28,7 @@ describe('ApiClient class', () => {
});

it('can get serverAddress', () => {
expect(client.serverAddress()).toBe('http://demo.jellyfin.org/stable');
expect(client.serverAddress()).toBe('https://demo.jellyfin.org/stable');
});

it('can get appName', () => {
@@ -56,17 +56,19 @@ describe('ApiClient class', () => {
});

it('can change server address', () => {
expect(client.serverAddress('http://demo.jellyfin.org/nightly')).toBe('http://demo.jellyfin.org/nightly');
expect(client.serverAddress('https://demo.jellyfin.org/nightly')).toBe('https://demo.jellyfin.org/nightly');
});

it('can get a URL', () => {
expect(client.getUrl('/System/Info/Public')).toBe('http://demo.jellyfin.org/stable/System/Info/Public');
});
describe('getUrl()', () => {
it('can get a URL', () => {
expect(client.getUrl('/System/Info/Public')).toBe('https://demo.jellyfin.org/stable/System/Info/Public');
});

it('can throw error on getting an empty URL', () => {
expect(() => {
client.getUrl();
}).toThrow(Error);
it('can throw error on getting an empty URL', () => {
expect(() => {
client.getUrl();
}).toThrow(Error);
});
});

it('can set valid headers', () => {
@@ -79,4 +81,20 @@ describe('ApiClient class', () => {
'MediaBrowser Client="Jellyfin Web", Device="Firefox", DeviceId="TW96aWxsYS81LjAgKFgxMTsgTGludXggeDg2XzY0OyBydjo3NC4wKSBHZWNrby8yMDEwMDEwMSBGaXJlZm94Lzc0LjB8MTU4NDkwMTA5OTY3NQ11", Version="10.5.0"'
});
});

describe('authenticateUserByName()', () => {
it('can authenticate successfully', async () => {
const response = await client.authenticateUserByName('demo');
expect(response.User).toBeDefined();
expect(response.User.Name).toBe('demo');
});

it('will reject with no username', () => {
return expect(client.authenticateUserByName()).rejects.toBeUndefined();
});

it('will reject with invalid credentials', () => {
return expect(client.authenticateUserByName('apiclienttest', 'password')).rejects.toBeDefined();
});
});
});
@@ -2564,6 +2564,13 @@ emojis-list@^3.0.0:
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78"
integrity sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==

encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
integrity sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=
dependencies:
iconv-lite "~0.4.13"

end-of-stream@^1.0.0, end-of-stream@^1.1.0:
version "1.4.4"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
@@ -3417,7 +3424,7 @@ human-signals@^1.1.1:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==

iconv-lite@0.4.24, iconv-lite@^0.4.24:
iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@~0.4.13:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
@@ -3704,7 +3711,7 @@ is-regex@^1.0.5:
dependencies:
has "^1.0.3"

is-stream@^1.1.0:
is-stream@^1.0.1, is-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
@@ -3768,6 +3775,14 @@ isobject@^3.0.0, isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=

isomorphic-fetch@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -4801,6 +4816,14 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
integrity sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
@@ -6791,6 +6814,11 @@ whatwg-encoding@^1.0.5:
dependencies:
iconv-lite "0.4.24"

whatwg-fetch@>=0.10.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"
integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==

whatwg-mimetype@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"

0 comments on commit d3a565c

Please sign in to comment.