Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions tests/BotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

it('can be instantiated with default parameters', function () {
$bot = new Bot(
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot)->toBeInstanceOf(Bot::class)
Expand All @@ -19,8 +19,8 @@
$event = new Event();
$bot = new Bot(
event: $event,
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot->event)->toBe($event);
Expand All @@ -29,8 +29,8 @@
it('can be instantiated with custom platform', function () {
$bot = new Bot(
platform: 'github',
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot->event->platform)->toBe('github');
Expand All @@ -40,17 +40,17 @@
$setting = new Setting();
$bot = new Bot(
setting: $setting,
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot->setting)->toBe($setting);
});

it('sets default platform when not specified', function () {
$bot = new Bot(
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot->event->platform)->toBe('github');
Expand All @@ -60,17 +60,17 @@
// This should not throw if the platform file exists
$bot = new Bot(
platform: 'github',
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot->event->getEventConfig())->toBeArray();
});

it('validates setting file on construction', function () {
$bot = new Bot(
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);

expect($bot->setting->getSettingFile())->not->toBeEmpty();
Expand Down
18 changes: 9 additions & 9 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

beforeEach(function () {
$this->bot = new Bot(
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);
});

Expand All @@ -14,7 +14,7 @@
});

it('platform can be set for event with platform parameter', function () {
$this->bot->setPlatFormForEvent('gitlab', __DIR__.'/../config/jsons/gitlab-events.json');
$this->bot->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
expect($this->bot->event->platform)->toBe('gitlab');
});

Expand All @@ -24,33 +24,33 @@
});

it('platform can be set for event with platform file', function () {
$this->bot->setPlatFormForEvent('gitlab', __DIR__.'/../config/jsons/gitlab-events.json');
$this->bot->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
expect($this->bot->event->platform)->toBe('gitlab')
->and($this->bot->event->platformFile)
->toBe(__DIR__.'/../config/jsons/gitlab-events.json');
->toBe(__DIR__ . '/../config/jsons/gitlab-events.json');
});

it('can get json config for event - github', function () {
$this->bot->setPlatFormForEvent('github', __DIR__.'/../config/jsons/github-events.json');
$this->bot->setPlatFormForEvent('github', __DIR__ . '/../config/jsons/github-events.json');
expect($this->bot->event->getEventConfig())->toBeArray()
->and($this->bot->event->getEventConfig())->toHaveKey('issue_comment');
});

it('can get json config for event - gitlab', function () {
$this->bot->setPlatFormForEvent('gitlab', __DIR__.'/../config/jsons/gitlab-events.json');
$this->bot->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
expect($this->bot->event->getEventConfig())->toBeArray()
->and($this->bot->event->getEventConfig())->toHaveKey('tag_push');
});

it('setting file is valid', function () {
$this->bot->updateSetting(__DIR__.'/../config/jsons/tgn-settings.json');
$this->bot->updateSetting(__DIR__ . '/../config/jsons/tgn-settings.json');
$this->bot->validateSettingFile();

expect($this->bot->setting->getSettings())->toBeArray();
});

it('platform file is valid', function () {
$this->bot->setPlatFormForEvent('github', __DIR__.'/../config/jsons/github-events.json');
$this->bot->setPlatFormForEvent('github', __DIR__ . '/../config/jsons/github-events.json');
$this->bot->validatePlatformFile();

expect($this->bot->event->getEventConfig())->toBeArray();
Expand Down
6 changes: 3 additions & 3 deletions tests/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use CSlant\TelegramGitNotifier\Notifier;

beforeEach(function () {
$this->notifier = new Notifier(platformFile: __DIR__.'/../config/jsons/github-events.json');
$this->notifier = new Notifier(platformFile: __DIR__ . '/../config/jsons/github-events.json');
});

it('validates that the event files exist', function () {
$this->notifier->setPlatFormForEvent('gitlab', __DIR__.'/../config/jsons/gitlab-events.json');
$this->notifier->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
expect($this->notifier->event->getEventConfig())->toBeArray()
->and($this->notifier->event->getEventConfig())->toHaveKey('tag_push');

$this->notifier->setPlatFormForEvent('github', __DIR__.'/../config/jsons/github-events.json');
$this->notifier->setPlatFormForEvent('github', __DIR__ . '/../config/jsons/github-events.json');
expect($this->notifier->event->getEventConfig())->toBeArray()
->and($this->notifier->event->getEventConfig())
->toHaveKey('issue_comment');
Expand Down
10 changes: 5 additions & 5 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

beforeEach(function () {
$this->bot = new Bot(
platformFile: __DIR__.'/../config/jsons/github-events.json',
settingFile: __DIR__.'/../config/jsons/tgn-settings.json'
platformFile: __DIR__ . '/../config/jsons/github-events.json',
settingFile: __DIR__ . '/../config/jsons/tgn-settings.json'
);
$this->validator = new Validator($this->bot->setting, $this->bot->event);
});
Expand All @@ -29,21 +29,21 @@
});

it('can validate the event that has no action to send a notification - gitlab', function () {
$this->bot->setPlatFormForEvent('gitlab', __DIR__.'/../config/jsons/gitlab-events.json');
$this->bot->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
$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', __DIR__.'/../config/jsons/gitlab-events.json');
$this->bot->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
$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', __DIR__.'/../config/jsons/gitlab-events.json');
$this->bot->setPlatFormForEvent('gitlab', __DIR__ . '/../config/jsons/gitlab-events.json');
$result = $this->validator->isAccessEvent('gitlab', 'merge_request', (object)[]);
expect($result)->toBeFalse();
});
Loading