-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from tanhongit/test
Test
- Loading branch information
Showing
13 changed files
with
202 additions
and
13 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
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,24 @@ | ||
#!/bin/bash | ||
|
||
echo "Setting up config files for Telegram Git Notifier..." | ||
|
||
mkdir -p storage/json/tgn | ||
|
||
json_files=( | ||
"github-events.json" | ||
"gitlab-events.json" | ||
"tgn-settings.json" | ||
) | ||
|
||
for file in "${json_files[@]}"; do | ||
if [ ! -f "storage/json/tgn/$file" ]; then | ||
cp "./config/jsons/$file" "storage/json/tgn/$file" | ||
echo "Created storage/json/tgn/$file" | ||
fi | ||
done | ||
|
||
if [[ "$(uname -s -r)" == *"Linux"* && "$(cat /etc/os-release)" == *"Ubuntu"* ]]; then | ||
chmod 777 storage/json/tgn/*.json | ||
fi | ||
|
||
echo "Telegram Git Notifier config files are ready!" |
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<coverage> | ||
<report> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Telegram Git Notifier Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use LbilTech\TelegramGitNotifier\Bot; | ||
|
||
beforeEach(function () { | ||
$this->bot = new Bot(); | ||
}); | ||
|
||
it('should return true', function () { | ||
$this->assertTrue(true); | ||
}); | ||
|
||
it('platform can be set for event with platform parameter', function () { | ||
$this->bot->setPlatFormForEvent('gitlab'); | ||
expect($this->bot->event->platform)->toBe('gitlab'); | ||
}); | ||
|
||
it('platform can be set for event with null parameter', function () { | ||
$this->bot->setPlatFormForEvent(); | ||
expect($this->bot->event->platform)->toBe('github'); | ||
}); | ||
|
||
it('platform can be set for event with platform file', function () { | ||
$this->bot->setPlatFormForEvent('gitlab', 'storage/json/tgn/gitlab-events.json'); | ||
expect($this->bot->event->platform)->toBe('gitlab'); | ||
expect($this->bot->event->getPlatformFile())->toBe('storage/json/tgn/gitlab-events.json'); | ||
}); | ||
|
||
it('can get json config for event - github', function () { | ||
$this->bot->setPlatFormForEvent(); | ||
expect($this->bot->event->getEventConfig())->toBeArray(); | ||
expect($this->bot->event->getEventConfig())->toHaveKey('issue_comment'); | ||
}); | ||
|
||
it('can get json config for event - gitlab', function () { | ||
$this->bot->setPlatFormForEvent('gitlab', 'storage/json/tgn/gitlab-events.json'); | ||
expect($this->bot->event->getEventConfig())->toBeArray(); | ||
expect($this->bot->event->getEventConfig())->toHaveKey('tag_push'); | ||
}); |
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,25 @@ | ||
<?php | ||
|
||
use LbilTech\TelegramGitNotifier\Notifier; | ||
|
||
beforeEach(function () { | ||
$this->nofitier = new Notifier(); | ||
}); | ||
|
||
it('validates that the event files exist', function () { | ||
$this->nofitier->setPlatFormForEvent('gitlab', 'storage/json/tgn/gitlab-events.json'); | ||
expect($this->nofitier->event->getEventConfig())->toBeArray(); | ||
expect($this->nofitier->event->getEventConfig())->toHaveKey('tag_push'); | ||
|
||
$this->nofitier->setPlatFormForEvent('github', 'storage/json/tgn/github-events.json'); | ||
expect($this->nofitier->event->getEventConfig())->toBeArray(); | ||
expect($this->nofitier->event->getEventConfig())->toHaveKey('issue_comment'); | ||
}); | ||
|
||
it('can parse notification chat IDs', function () { | ||
$chatThreadMapping = $this->nofitier->parseNotifyChatIds('-1201937489183;-1008168942527:46,2'); | ||
expect($chatThreadMapping)->toBeArray(); | ||
expect($chatThreadMapping)->toHaveKey('-1008168942527'); | ||
expect($chatThreadMapping['-1008168942527'])->toBeArray(); | ||
expect($chatThreadMapping['-1008168942527'])->toBe([0 => '46', 1 => '2']); | ||
}); |
Empty file.
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,48 @@ | ||
<?php | ||
|
||
use LbilTech\TelegramGitNotifier\Bot; | ||
use LbilTech\TelegramGitNotifier\Objects\Validator; | ||
|
||
beforeEach(function () { | ||
$this->bot = new Bot(); | ||
$this->bot->updateSetting('storage/json/tgn/setting.json'); | ||
$this->bot->setPlatFormForEvent(); | ||
$this->validator = new Validator($this->bot->setting, $this->bot->event); | ||
}); | ||
|
||
it('can validate the event that has no action to send a notification - GitHub', function () { | ||
$result = $this->validator->isAccessEvent('github', 'push', (object)[]); | ||
expect($result)->toBeTrue(); | ||
}); | ||
|
||
it('can validate the event that has an action to send a notification - GitHub', function () { | ||
$result = $this->validator->isAccessEvent('github', 'pull_request', (object)[ | ||
'action' => 'opened', | ||
]); | ||
expect($result)->toBeTrue(); | ||
}); | ||
|
||
it('can\'t validate the event that has an action but no payload to send a notification - GitHub', function () { | ||
$result = $this->validator->isAccessEvent('github', 'pull_request', (object)[]); | ||
expect($result)->toBeFalse(); | ||
}); | ||
|
||
it('can validate the event that has no action to send a notification - gitlab', function () { | ||
$this->bot->setPlatFormForEvent('gitlab'); | ||
$result = $this->validator->isAccessEvent('gitlab', 'push', (object)[]); | ||
expect($result)->toBeTrue(); | ||
}); | ||
|
||
it('can validate the event that has an action to send a notification - gitlab', function () { | ||
$this->bot->setPlatFormForEvent('gitlab'); | ||
$result = $this->validator->isAccessEvent('gitlab', 'merge_request', (object)[ | ||
'action' => 'open', | ||
]); | ||
expect($result)->toBeTrue(); | ||
}); | ||
|
||
it('can\'t validate the event that has an action but no payload to send a notification - gitlab', function () { | ||
$this->bot->setPlatFormForEvent('gitlab'); | ||
$result = $this->validator->isAccessEvent('gitlab', 'merge_request', (object)[]); | ||
expect($result)->toBeFalse(); | ||
}); |