-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtest.js
108 lines (91 loc) · 2.76 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
import assert from 'assert';
import xs from 'xstream';
import { assertSourcesSinks } from './helpers';
import * as ActionTypes from '../../ActionTypes';
import * as actions from '../../actions';
import { fetchReposByUser, searchUsers } from '../';
describe('Cycles', function() {
describe('fetchReposByUser', function() {
it('should emit HTTP requests given ACTIONs', function(done) {
const user1 = 'lmatteis';
const user2 = 'luca';
const actionSource = {
a: actions.requestReposByUser(user1),
b: actions.requestReposByUser(user2)
};
const httpSource = {
select: () => null
}
const httpSink = {
x: {
url: `https://api.github.com/users/${user1}/repos`,
category: 'users'
},
y: {
url: `https://api.github.com/users/${user2}/repos`,
category: 'users'
}
};
// Asserts that the sources, trigger the provided sinks,
// when executing the fetchReposByUser function
assertSourcesSinks({
ACTION: { 'ab|': actionSource },
HTTP: { '--|': httpSource }
}, {
HTTP: { 'xy|': httpSink }
}, fetchReposByUser, done);
});
it('should emit ACTION given HTTP response', function(done) {
const user1 = 'lmatteis';
const user2 = 'luca';
const response = { body: { foo: 'bar' } };
const actionSource = {
a: actions.requestReposByUser(user1)
};
const httpSource = {
select: () => ({
r: xs.of(response)
})
};
const actionSink = {
a: actions.receiveUserRepos(user1, response.body)
};
assertSourcesSinks({
ACTION: { 'a|': actionSource },
HTTP: { 'r|': httpSource }
}, {
ACTION: { 'a|': actionSink }
}, fetchReposByUser, done);
});
});
describe('searchUsers', () => {
it('should emit HTTP requests given many debounced ACTIONs, and should emit ACTION given HTTP response', (done) => {
const actionSource = {
a: actions.searchUsers('l'),
b: actions.searchUsers('lu'),
c: actions.searchUsers('luc')
};
const httpSource = {
select: () => ({
r: xs.of({ body: { items: ['foo'] } })
})
}
const httpSink = {
a: {
url: `https://api.github.com/search/users?q=luc`,
category: 'query'
}
}
const actionSink = {
r: actions.receiveUsers(['foo']),
}
assertSourcesSinks({
ACTION: { '-a-b-c----|': actionSource },
HTTP: { '---r------|': httpSource },
}, {
HTTP: { '---------a|': httpSink },
ACTION: { '---r------|': actionSink },
}, searchUsers, done, { interval: 200 });
})
})
});