2023-11-14 18:42:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function set_up() {
|
|
|
|
source ./src/misc.sh
|
|
|
|
source ./src/github.sh
|
|
|
|
}
|
|
|
|
|
2024-04-16 08:35:06 -07:00
|
|
|
pr_number=123
|
|
|
|
files_to_ignore=''
|
|
|
|
ignore_line_deletions='false'
|
|
|
|
|
|
|
|
function test_should_count_changes() {
|
|
|
|
mock curl cat ./tests/fixtures/pull_request_api
|
|
|
|
|
|
|
|
assert_match_snapshot "$(github::calculate_total_modifications "$pr_number" "${files_to_ignore[*]}" "$ignore_line_deletions")"
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_should_count_changes_ignore_deletions() {
|
|
|
|
ignore_line_deletions='true'
|
|
|
|
|
|
|
|
mock curl cat ./tests/fixtures/pull_request_api
|
|
|
|
|
|
|
|
assert_match_snapshot "$(github::calculate_total_modifications "$pr_number" "${files_to_ignore[*]}" "$ignore_line_deletions")"
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: when `files_to_ignore` is set, we have to invoke the PR files API and iterate each file
|
|
|
|
# one at at time. This is why the mock call is diffent in the subsequent test cases
|
2023-11-14 18:42:54 +01:00
|
|
|
function test_should_ignore_files_with_glob() {
|
2024-04-16 08:35:06 -07:00
|
|
|
files_to_ignore=("*.lock" ".editorconfig")
|
|
|
|
|
|
|
|
mock curl cat ./tests/fixtures/pull_request_files_api
|
2023-11-14 18:42:54 +01:00
|
|
|
|
2024-04-16 08:35:06 -07:00
|
|
|
assert_match_snapshot "$(github::calculate_total_modifications "$pr_number" "${files_to_ignore[*]}" "$ignore_line_deletions")"
|
2023-11-14 18:42:54 +01:00
|
|
|
}
|
2024-04-16 08:35:06 -07:00
|
|
|
|
|
|
|
function test_should_ignore_files_with_glob_ignore_deletions() {
|
|
|
|
files_to_ignore=("*.lock" ".editorconfig")
|
|
|
|
ignore_line_deletions='true'
|
|
|
|
|
|
|
|
mock curl cat ./tests/fixtures/pull_request_files_api
|
|
|
|
|
|
|
|
assert_match_snapshot "$(github::calculate_total_modifications "$pr_number" "${files_to_ignore[*]}" "$ignore_line_deletions")"
|
|
|
|
}
|