Skip to content

Commit 23ed35b

Browse files
committed
Builder for creating test Commits
1 parent 8434c08 commit 23ed35b

2 files changed

Lines changed: 60 additions & 16 deletions

File tree

test/builder/commit.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import moment from 'moment';
2+
3+
import Commit from '../../lib/models/commit';
4+
5+
class CommitBuilder {
6+
constructor() {
7+
this._sha = '0123456789abcdefghij0123456789abcdefghij';
8+
this._authorEmail = 'default@email.com';
9+
this._authorDate = moment('2018-11-28T12:00:00', moment.ISO_8601).unix();
10+
this._coAuthors = [];
11+
this._messageSubject = 'subject';
12+
this._messageBody = 'body';
13+
}
14+
15+
sha(newSha) {
16+
this._sha = newSha;
17+
return this;
18+
}
19+
20+
authorEmail(newEmail) {
21+
this._authorEmail = newEmail;
22+
return this;
23+
}
24+
25+
authorDate(timestamp) {
26+
this._authorDate = timestamp;
27+
return this;
28+
}
29+
30+
messageSubject(subject) {
31+
this._messageSubject = subject;
32+
return this;
33+
}
34+
35+
messageBody(body) {
36+
this._messageBody = body;
37+
return this;
38+
}
39+
40+
build() {
41+
return new Commit({
42+
sha: this._sha,
43+
authorEmail: this._authorEmail,
44+
authorDate: this._authorDate,
45+
coAuthors: this._coAuthors,
46+
messageSubject: this._messageSubject,
47+
messageBody: this._messageBody,
48+
});
49+
}
50+
}
51+
52+
export function commitBuilder() {
53+
return new CommitBuilder();
54+
}

test/models/commit.test.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
import moment from 'moment';
21
import dedent from 'dedent-js';
32

4-
import Commit, {nullCommit} from '../../lib/models/commit';
3+
import {nullCommit} from '../../lib/models/commit';
4+
import {commitBuilder} from '../builder/commit';
55

66
describe('Commit', function() {
7-
function buildCommit(override = {}) {
8-
return new Commit({
9-
sha: '0123456789abcdefghij0123456789abcdefghij',
10-
authorEmail: 'me@email.com',
11-
coAuthors: [],
12-
authorDate: moment('2018-11-28T12:00:00', moment.ISO_8601).unix(),
13-
messageSubject: 'subject',
14-
messageBody: 'body',
15-
...override,
16-
});
17-
}
18-
197
describe('isBodyLong()', function() {
208
it('returns false if the commit message body is short', function() {
21-
assert.isFalse(buildCommit({messageBody: 'short'}).isBodyLong());
9+
const commit = commitBuilder().messageBody('short').build();
10+
assert.isFalse(commit.isBodyLong());
2211
});
2312

2413
it('returns true if the commit message body is long', function() {
@@ -41,7 +30,8 @@ describe('Commit', function() {
4130
delicatissimi sea in. Est id putent accusata convenire, no tibique molestie accommodare quo, cu est fuisset
4231
offendit evertitur.
4332
`;
44-
assert.isTrue(buildCommit({messageBody}).isBodyLong());
33+
const commit = commitBuilder().messageBody(messageBody).build();
34+
assert.isTrue(commit.isBodyLong());
4535
});
4636

4737
it('returns false for a null commit', function() {

0 commit comments

Comments
 (0)