Skip to content

Commit

Permalink
#6 - Another more integration tests for StarsUp bot
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin committed Apr 13, 2020
1 parent e584fca commit e29d7f3
Show file tree
Hide file tree
Showing 36 changed files with 504 additions and 47 deletions.
19 changes: 6 additions & 13 deletions src/main/java/dev/iakunin/codexiabot/bot/StarsUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,10 @@ public void run() {
.forEach(this::processStatList)
;


// Тест-кейсы с двумя последовательными запусками с изменениями состояния бота (бот сработал)
// Тест-кейсы с двумя последовательными запусками с изменениями состояния github-статистики
// (бот может как сработать, так и нет)


// - Remote-call exception with transaction rollback

log.info("Exiting from {}", this.getClass().getName());
}

// @todo #6 add test case with transaction rollback
@Transactional
protected void processStatList(Deque<GithubRepoStat> deque) {
final GithubRepoStat first = deque.getFirst();
Expand Down Expand Up @@ -114,6 +107,11 @@ protected void processStatList(Deque<GithubRepoStat> deque) {
)
);

this.starsUpResultRepository.save(
new StarsUpResult()
.setGithubRepo(last.getGithubRepo())
.setGithubRepoStat(last)
);
this.codexiaModule.sendReview(review);
this.codexiaModule.sendMeta(
review.getCodexiaProject(),
Expand All @@ -124,11 +122,6 @@ protected void processStatList(Deque<GithubRepoStat> deque) {
.map(CodexiaReview::getReason)
.collect(Collectors.joining(","))
);
this.starsUpResultRepository.save(
new StarsUpResult()
.setGithubRepo(last.getGithubRepo())
.setGithubRepoStat(last)
);
}

private boolean shouldReviewBeSubmitted(GithubApi firstStat, GithubApi lastStat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"type": "java.lang.String",
"description": "Cron expression for bot.found-on-hackernews."
},
{
"name": "app.cron.bot.stars-up",
"type": "java.lang.String",
"description": "Cron expression for bot.stars-up."
},
{
"name": "app.cron.bot.found-on-reddit",
"type": "java.lang.String",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
app.cron.bot.found-on-hackernews=5 * * * * *
app.cron.bot.found-on-reddit=55 * * * * *
app.cron.bot.stars-up=0 30 * * * *

app.cron.codexia.codexia-parser=45 * * * * *
app.cron.codexia.missing-filler=0 0 0 * * *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,70 @@ public void noStarsUpResults_githubRepoWithTwoStats_happyPath() {
public void noStarsUpResults_githubRepoWithThreeStats_happyPath() {
starsUp.run();
}

@Test
@Transactional
@DataSet(
value = "db-rider/bot/initial/oneStarsUpResult_githubRepoWithThreeStats_happyPath.yml",
cleanAfter = true, cleanBefore = true, disableConstraints = true
)
@ExpectedDataSet("db-rider/bot/expected/oneStarsUpResult_githubRepoWithThreeStats_happyPath.yml")
public void oneStarsUpResult_githubRepoWithThreeStats_happyPath() {
starsUp.run();
}

@Test
@Transactional
@DataSet(
value = "db-rider/bot/initial/oneStarsUpResult_githubRepoWithFourStats_happyPath.yml",
cleanAfter = true, cleanBefore = true, disableConstraints = true
)
@ExpectedDataSet("db-rider/bot/expected/oneStarsUpResult_githubRepoWithFourStats_happyPath.yml")
public void oneStarsUpResult_githubRepoWithFourStats_happyPath() {
starsUp.run();
}

@Test
@Transactional
@DataSet(
value = "db-rider/bot/initial/oneStarsUpResult_noNewGithubStats.yml",
cleanAfter = true, cleanBefore = true, disableConstraints = true
)
@ExpectedDataSet("db-rider/bot/expected/oneStarsUpResult_noNewGithubStats.yml")
public void oneStarsUpResult_noNewGithubStats() {
starsUp.run();
}

@Test
@Transactional
@DataSet(
value = "db-rider/bot/initial/oneStarsUpResult_starsDecrease.yml",
cleanAfter = true, cleanBefore = true, disableConstraints = true
)
@ExpectedDataSet("db-rider/bot/expected/oneStarsUpResult_starsDecrease.yml")
public void oneStarsUpResult_starsDecrease() {
starsUp.run();
}

@Test
@Transactional
@DataSet(
value = "db-rider/bot/initial/oneStarsUpResult_starsIncreaseLessThan10.yml",
cleanAfter = true, cleanBefore = true, disableConstraints = true
)
@ExpectedDataSet("db-rider/bot/expected/oneStarsUpResult_starsIncreaseLessThan10.yml")
public void oneStarsUpResult_starsIncreaseLessThan10() {
starsUp.run();
}

@Test
@Transactional
@DataSet(
value = "db-rider/bot/initial/oneStarsUpResult_starsIncreaseMoreThan10ButLessThan5Percents.yml",
cleanAfter = true, cleanBefore = true, disableConstraints = true
)
@ExpectedDataSet("db-rider/bot/expected/oneStarsUpResult_starsIncreaseMoreThan10ButLessThan5Percents.yml")
public void oneStarsUpResult_starsIncreaseMoreThan10ButLessThan5Percents() {
starsUp.run();
}
}
4 changes: 2 additions & 2 deletions src/test/resources/db-rider/bot/expected/emptyDatabase.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ codexia_review:
(was: 402 stars, now: 473 stars).
See the stars history
[here](https://star-history.t9t.io/#test-project1/test-repo1).
# @todo #6 here should be an assertion to `codexia_review_notification` table
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ codexia_review:
(was: 402 stars, now: 459 stars).
See the stars history
[here](https://star-history.t9t.io/#test-project1/test-repo1).
# @todo #6 here should be an assertion to `codexia_review_notification` table
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
stars_up_result:
stars_up_result: []

codexia_review:
codexia_review: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
stars_up_result:
-
github_repo_id: 1
github_repo_stat_id: 3
-
github_repo_id: 1
github_repo_stat_id: 5

codexia_review:
-
codexia_project_id: 5
author: "STARS_UP"
reason: "528"
text: >-
The repo gained 69 stars since 2020-02-16T18:46:09.652645Z
(was: 459 stars, now: 528 stars).
See the stars history
[here](https://star-history.t9t.io/#test-project1/test-repo1).
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
stars_up_result:
-
github_repo_id: 1
github_repo_stat_id: 3
-
github_repo_id: 1
github_repo_stat_id: 4

codexia_review:
-
codexia_project_id: 5
author: "STARS_UP"
reason: "502"
text: >-
The repo gained 43 stars since 2020-02-16T18:46:09.652645Z
(was: 459 stars, now: 502 stars).
See the stars history
[here](https://star-history.t9t.io/#test-project1/test-repo1).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
stars_up_result:
-
github_repo_id: 1
github_repo_stat_id: 3

codexia_review: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
stars_up_result:
-
github_repo_id: 1
github_repo_stat_id: 3

codexia_review: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
stars_up_result:
-
github_repo_id: 1
github_repo_stat_id: 3

codexia_review: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
stars_up_result:
-
github_repo_id: 1
github_repo_stat_id: 3

codexia_review: []
6 changes: 3 additions & 3 deletions src/test/resources/db-rider/bot/initial/emptyDatabase.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github_repo:
github_repo: []

github_repo_source:
github_repo_source: []

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ github_repo_stat:
github_repo_id: 1
type: "GITHUB_API"

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ github_repo_stat:
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 132}'

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ github_repo_stat:
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 414}'

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ github_repo_stat:
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 99}'

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ github_repo_stat:
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 132}'

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ github_repo_stat:
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 414}'

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ github_repo_stat:
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 123}'

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ github_repo_source:
source: "CODEXIA"
external_id: "12"

github_repo_stat:
github_repo_stat: []

stars_up_result:
stars_up_result: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
github_repo:
-
id: 1
uuid: "groovy: UUID.randomUUID().toString()"
external_id: "150713223"
full_name: "test-project1/test-repo1"

codexia_project:
-
id: 5
uuid: "groovy: UUID.randomUUID().toString()"
external_id: 12
coordinates: "test-project1/test-repo1"
author: "some-first-author"
author_id: 44
deleted: null
project_created_at: "2019-12-20 12:01:02"

github_repo_source:
-
id: 1
uuid: "groovy: UUID.randomUUID().toString()"
github_repo_id: 1
source: "CODEXIA"
external_id: "12"

github_repo_stat:
-
id: 1
uuid: "groovy: UUID.randomUUID().toString()"
github_repo_id: 1
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 402}'
created_at: "2020-02-11 10:06:16.123456"
-
id: 3
uuid: "groovy: UUID.randomUUID().toString()"
github_repo_id: 1
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 459}'
created_at: "2020-02-16 18:46:09.652645"
-
id: 4
uuid: "groovy: UUID.randomUUID().toString()"
github_repo_id: 1
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 502}'
created_at: "2020-02-21 07:12:34.333421"
-
id: 5
uuid: "groovy: UUID.randomUUID().toString()"
github_repo_id: 1
type: "GITHUB_API"
stat: '{"type": "GITHUB_API", "stars": 528}'
created_at: "2020-02-24 15:34:01.223344"

stars_up_result:
-
uuid: "groovy: UUID.randomUUID().toString()"
github_repo_id: 1
github_repo_stat_id: 3

codexia_review: []
Loading

0 comments on commit e29d7f3

Please sign in to comment.