-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathOrganizationsJSONAdapter.test.js
55 lines (46 loc) · 1.38 KB
/
OrganizationsJSONAdapter.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
import {isObservable} from 'rxjs';
import organizations from '../data/organizations';
import OrganizationsJSONAdapter from './OrganizationsJSONAdapter';
describe('Organization JSON Adapter', () => {
let ID;
let organizationsJSONAdapter;
beforeEach(() => {
[ID] = Object.keys(organizations);
organizationsJSONAdapter = new OrganizationsJSONAdapter(organizations);
});
afterEach(() => {
ID = null;
organizationsJSONAdapter = null;
});
describe('getOrg()', () => {
test('returns an observable', () => {
expect(isObservable(organizationsJSONAdapter.getOrg())).toBeTruthy();
});
test('emits an organization object', (done) => {
organizationsJSONAdapter.getOrg(ID).subscribe((org) => {
expect(org).toEqual(organizations[ID]);
done();
});
});
test('throws a proper error message', (done) => {
const wrongOrgID = 'wrongOrgID';
organizationsJSONAdapter.getOrg(wrongOrgID).subscribe(
() => {},
(error) => {
expect(error.message).toBe(`Could not find any organization with ID "${wrongOrgID}"`);
done();
},
);
});
test('completes the observable', (done) => {
organizationsJSONAdapter.getOrg(ID).subscribe(
() => {},
() => {},
() => {
expect(true).toBeTruthy();
done();
},
);
});
});
});