forked from sourcerer-io/sourcerer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(colleagues) - send colleagues info to server (APP-174) (sourcere…
- Loading branch information
Showing
5 changed files
with
188 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -555,59 +555,4 @@ class CodeLongevityTest : Spek({ | |
testRepo.destroy() | ||
} | ||
} | ||
|
||
given("'colleagues #1'") { | ||
val testRepoPath = "../CodeLongevity_colleagues1" | ||
val testRepo = TestRepo(testRepoPath) | ||
val testRehash = "rehash_colleagues1" | ||
val fileName = "test1.txt" | ||
val author1 = Author(testRepo.userName, testRepo.userEmail) | ||
val author2 = Author("Vasya Pupkin", "[email protected]") | ||
val emails = hashSetOf(author1.email, author2.email) | ||
|
||
val serverRepo = Repo(rehash = testRehash) | ||
val mockApi = MockApi(mockRepo = serverRepo) | ||
|
||
testRepo.createFile(fileName, listOf("line1", "line2")) | ||
testRepo.commit(message = "initial commit", | ||
author = author1, | ||
date = Calendar.Builder().setTimeOfDay(0, 0, 0) | ||
.build().time) | ||
|
||
testRepo.deleteLines(fileName, 1, 1) | ||
testRepo.commit(message = "delete line", | ||
author = author1, | ||
date = Calendar.Builder().setTimeOfDay(0, 1, 0) | ||
.build().time) | ||
|
||
testRepo.deleteLines(fileName, 0, 0) | ||
testRepo.commit(message = "delete line #2", | ||
author = author2, | ||
date = Calendar.Builder().setTimeOfDay(0, 1, 0) | ||
.build().time) | ||
|
||
val cl = CodeLongevity(serverRepo, emails, testRepo.git) | ||
cl.updateFromObservable(onError = { _ -> fail("exception") }, | ||
api = mockApi) | ||
|
||
it("'t1'") { | ||
val triple1 = cl.colleagues.get(author1.email)[0] | ||
assertEquals(triple1.first, author2.email, | ||
"Wrong colleague email #1") | ||
assertEquals(triple1.second, "1970-01", "Wrong colleague month #1") | ||
assertEquals(triple1.third, 60, "Wrong colleague vicinity #1") | ||
|
||
val triple2 = cl.colleagues.get(author2.email)[0] | ||
assertEquals(triple2.first, author1.email, | ||
"Wrong colleague email #1") | ||
assertEquals(triple2.second, "1970-01", "Wrong colleague month #1") | ||
assertEquals(triple2.third, 60, "Wrong colleague vicinity #1") | ||
} | ||
|
||
afterGroup { | ||
CodeLongevity(Repo(rehash = testRehash), emails, testRepo.git) | ||
.dropSavedData() | ||
testRepo.destroy() | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Copyright 2017 Sourcerer Inc. All Rights Reserved. | ||
// Author: Alexander Surkov ([email protected]) | ||
|
||
package test.tests.hashers | ||
|
||
import app.api.MockApi | ||
import app.FactCodes | ||
import app.hashers.CodeLine | ||
import app.hashers.CodeLineAges | ||
import app.hashers.CodeLongevity | ||
import app.hashers.RevCommitLine | ||
import app.model.* | ||
|
||
import test.utils.TestRepo | ||
|
||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
import kotlin.test.fail | ||
|
||
import org.eclipse.jgit.revwalk.RevCommit | ||
|
||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.given | ||
import org.jetbrains.spek.api.dsl.it | ||
|
||
import java.util.Calendar | ||
import kotlin.test.assertNotNull | ||
|
||
/** | ||
* Testing class. | ||
*/ | ||
class ColleaguesTest : Spek({ | ||
given("'colleagues #1'") { | ||
val testRepoPath = "../CodeLongevity_colleagues1" | ||
val testRepo = TestRepo(testRepoPath) | ||
val testRehash = "rehash_colleagues1" | ||
val fileName = "test1.txt" | ||
val author1 = Author(testRepo.userName, testRepo.userEmail) | ||
val author2 = Author("Vasya Pupkin", "[email protected]") | ||
val emails = hashSetOf(author1.email, author2.email) | ||
|
||
val serverRepo = Repo(rehash = testRehash) | ||
val mockApi = MockApi(mockRepo = serverRepo) | ||
|
||
testRepo.createFile(fileName, listOf("line1", "line2")) | ||
testRepo.commit(message = "initial commit", | ||
author = author1, | ||
date = Calendar.Builder().setTimeOfDay(0, 0, 0) | ||
.build().time) | ||
|
||
testRepo.deleteLines(fileName, 1, 1) | ||
testRepo.commit(message = "delete line", | ||
author = author1, | ||
date = Calendar.Builder().setTimeOfDay(0, 1, 0) | ||
.build().time) | ||
|
||
testRepo.deleteLines(fileName, 0, 0) | ||
testRepo.commit(message = "delete line #2", | ||
author = author2, | ||
date = Calendar.Builder().setTimeOfDay(0, 1, 0) | ||
.build().time) | ||
|
||
val cl = CodeLongevity(serverRepo, emails, testRepo.git) | ||
cl.updateFromObservable(onError = { _ -> fail("exception") }, | ||
api = mockApi) | ||
|
||
it("'t1'") { | ||
val triple1 = cl.colleagues.get(author1.email)[0] | ||
assertEquals(triple1.first, author2.email, | ||
"Wrong colleague email #1") | ||
assertEquals(triple1.second, "1970-01", "Wrong colleague month #1") | ||
assertEquals(triple1.third, 60, "Wrong colleague vicinity #1") | ||
|
||
val triple2 = cl.colleagues.get(author2.email)[0] | ||
assertEquals(triple2.first, author1.email, | ||
"Wrong colleague email #1") | ||
assertEquals(triple2.second, "1970-01", "Wrong colleague month #1") | ||
assertEquals(triple2.third, 60, "Wrong colleague vicinity #1") | ||
} | ||
|
||
afterGroup { | ||
CodeLongevity(Repo(rehash = testRehash), emails, testRepo.git) | ||
.dropSavedData() | ||
testRepo.destroy() | ||
} | ||
} | ||
|
||
given("'colleagues stats'") { | ||
val testRepoPath = "../CodeLongevity_colleagues_stats" | ||
val testRepo = TestRepo(testRepoPath) | ||
val testRehash = "rehash_lngstats2" | ||
val fileName = "test1.txt" | ||
val author1 = Author(testRepo.userName, testRepo.userEmail) | ||
val author2 = Author("Vasya Pupkin", "[email protected]") | ||
val emails = hashSetOf(author1.email, author2.email) | ||
|
||
val serverRepo = Repo(rehash = testRehash) | ||
val mockApi = MockApi(mockRepo = serverRepo) | ||
|
||
testRepo.createFile(fileName, listOf("line1", "line2")) | ||
testRepo.commit(message = "initial commit", | ||
author = author1, | ||
date = Calendar.Builder().setTimeOfDay(0, 0, 0) | ||
.build().time) | ||
|
||
testRepo.deleteLines(fileName, 1, 1) | ||
testRepo.commit(message = "delete line", | ||
author = author2, | ||
date = Calendar.Builder().setTimeOfDay(0, 1, 0) | ||
.build().time) | ||
|
||
testRepo.insertLines(fileName, 1, listOf("line in the end")) | ||
testRepo.commit(message = "insert line", | ||
author = author2, | ||
date = Calendar.Builder().setTimeOfDay(0, 10, 0) | ||
.build().time) | ||
|
||
testRepo.deleteLines(fileName, 1, 1) | ||
testRepo.commit(message = "delete line #2", | ||
author = author1, | ||
date = Calendar.Builder().setTimeOfDay(0, 20, 0) | ||
.build().time) | ||
|
||
CodeLongevity(serverRepo, emails, testRepo.git) | ||
.updateFromObservable(onError = { _ -> fail("exception") }, | ||
api = mockApi) | ||
|
||
it("'t1'") { | ||
for (f in mockApi.receivedFacts) { | ||
println(f) | ||
} | ||
assertTrue(mockApi.receivedFacts.contains( | ||
Fact(repo = serverRepo, | ||
code = FactCodes.COLLEAGUES, | ||
value = author2.email, | ||
value2 = author1.email, | ||
value3 = (60).toString()) | ||
)) | ||
} | ||
|
||
afterGroup { | ||
CodeLongevity(Repo(rehash = testRehash), emails, testRepo.git) | ||
.dropSavedData() | ||
testRepo.destroy() | ||
} | ||
} | ||
}) |