Skip to content

Commit

Permalink
add installationId, use name, use mockResolvedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
raboid authored and mfix22 committed Jan 9, 2019
1 parent 004fea4 commit cc79510
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ exports.installed = (robot, airtable) => async ({
payload: { installation, repositories, repositories_added }
}) => {
const {
id: installationId,
account: { login, type }
} = installation

Expand All @@ -10,7 +11,13 @@ exports.installed = (robot, airtable) => async ({
try {
await Promise.all(
repos.map(repo =>
airtable('installed').create({ login, type, repo: repo.full_name, private: repo.private })
airtable('installed').create({
login,
type,
repo: repo.name,
private: repo.private,
installationId
})
)
)
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/added.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = ({ action = 'added', repositories_added }) => ({
payload: {
action,
installation: {
id: 533899,
id: 42,
account: {
login: 'ranger',
id: 1,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/installed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = ({ action = 'created', repositories }) => ({
payload: {
action,
installation: {
id: 533899,
id: 42,
account: {
login: 'ranger',
id: 1,
Expand Down
19 changes: 7 additions & 12 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,8 @@ jest.mock(
() =>
class MockAirtable {
constructor() {
this.create = jest.fn(() => {
return Promise.resolve()
})
this.base = () => () => {
return {
create: this.create
}
}
this.create = jest.fn().mockResolvedValue()
this.base = () => () => ({ create: this.create })
}
}
)
Expand Down Expand Up @@ -603,8 +597,8 @@ describe('Bot', () => {
repos => installedPayload({ repositories: repos })
])('Will track installations', async createPayload => {
const repos = [
{ full_name: 'ranger/test-0', private: true },
{ full_name: 'ranger/test-1', private: false }
{ name: 'ranger/test-0', private: true },
{ name: 'ranger/test-1', private: false }
]

await robot.receive(createPayload(repos))
Expand All @@ -613,8 +607,9 @@ describe('Bot', () => {
expect(airtable('installed').create).toHaveBeenCalledWith({
login: 'ranger',
type: 'User',
repo: repo.full_name,
private: repo.private
repo: repo.name,
private: repo.private,
installationId: 42
})
})
})
Expand Down

0 comments on commit cc79510

Please # to comment.