-
-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathlib.meetup.test.js
103 lines (90 loc) · 4.55 KB
/
lib.meetup.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
import Meetup from '../server/lib/meetup';
import { expect } from 'chai';
import nock from 'nock';
import nockMeetup from './mocks/meetup.nock';
const collective = {
slug: 'opencollective',
users: [{
name: 'Github',
website: 'https://github.com',
tier: 'sponsor',
totalDonations: 100
},{
name: 'Xavier',
tier: 'backer',
website: 'https://twitter.com/xdamman',
totalDonations: 50
},{
name: 'Pia',
tier: 'backer',
website: 'https://twitter.com/piamancini',
totalDonations: 70
},{
name: 'Gitlab',
tier: 'sponsor',
totalDonations: 500
}]
};
const meetupAccount = {
service: 'meetup',
username: 'opencollective',
token: '620459537f4174273a5d4g535321445',
CollectiveId: 1
}
describe('meetup lib', () => {
before(nockMeetup);
after(() => {
nock.cleanAll();
});
it("syncCollective fails if no api key set", () => {
const meetup = new Meetup();
meetup.catch(e => {
expect(e).to.exist;
expect(e.code).to.equal(400);
});
});
it("generates the list of sponsors sorted by total donations", () => {
const meetup = new Meetup(meetupAccount, collective);
const header = meetup.makeHeader();
const expectedHeader = `<p>Thank you to our sponsors Gitlab and <a href="https://github.com">Github</a></p> <p><a href="https://opencollective.com/${collective.slug}#sponsors"><img src="https://opencollective.com/${collective.slug}/sponsors.png?width=700"></a></p>`;
expect(header).to.equal(expectedHeader);
});
it("shows the list of backers if no sponsors", () => {
const collectiveWithoutSponsors = Object.assign({}, collective, { users: collective.users.slice(1,3)});
const meetup = new Meetup(meetupAccount, collectiveWithoutSponsors);
const header = meetup.makeHeader();
const expectedHeader = `<p>Thank you to our backers <a href="https://twitter.com/piamancini">Pia</a> and <a href="https://twitter.com/xdamman">Xavier</a></p> <p><a href="https://opencollective.com/opencollective#backers"><img src="https://opencollective.com/opencollective/backers.png?width=700"></a></p>`;
expect(header).to.equal(expectedHeader);
});
it("adds/removes the header when no backers", () => {
const collectiveWithoutBackers = Object.assign({}, collective, { users: [] });
const description = "<p>Hello World</p>";
const meetup = new Meetup(meetupAccount, collectiveWithoutBackers);
const header = meetup.makeHeader();
const descriptionWithHeader = meetup.generateNewDescription('addHeader', description);
const descriptionWithoutHeader = meetup.generateNewDescription('removeHeader', descriptionWithHeader);
expect(header).to.equal(`<p><a href="https://opencollective.com/opencollective#backers"><img src="https://opencollective.com/opencollective/backers.png?width=700"></a></p>`);
expect(descriptionWithHeader).to.equal(`<p><a href="https://opencollective.com/opencollective#backers"><img src="https://opencollective.com/opencollective/backers.png?width=700"></a></p> <p>Hello World</p>`);
expect(descriptionWithoutHeader).to.equal(description);
});
it("adds the header to the next meetup", (done) => {
const meetup = new Meetup(meetupAccount, collective);
meetup.syncCollective('addHeader').then(result => {
expect(result.length).to.equal(1);
const expectedDescription = `<p>Thank you to our sponsors Gitlab and <a href="https://github.com">Github</a></p> <p><a href="https://opencollective.com/opencollective#sponsors"><a href="https://opencollective.com/opencollective/sponsors.png?width=700" class="linkified">https://opencollective.com/opencollective/sponsors.png?width=700</a></a></p> <p>We\'ll share how meetups are currently using OpenCollective to raise money - through donations and/or memberships - and increasing their impact on the world.</p> <p>Also a good chance to meet our core team - Xavier, Pia and Aseem.</p>`;
expect(result[0].description).to.equal(expectedDescription);
done();
})
.catch(done);
});
it("removes the header from the next meetup", (done) => {
const meetup = new Meetup(meetupAccount, collective);
meetup.syncCollective('removeHeader').then(result => {
expect(result.length).to.equal(1);
const expectedDescription = `<p>We\'ll share how meetups are currently using OpenCollective to raise money - through donations and/or memberships - and increasing their impact on the world.</p> <p>Also a good chance to meet our core team - Xavier, Pia and Aseem.</p>`;
expect(result[0].description).to.equal(expectedDescription);
done();
})
.catch(done);
});
});