Skip to content

Commit 100e52b

Browse files
feat: adding tests..
1 parent d39de07 commit 100e52b

File tree

5 files changed

+685
-11
lines changed

5 files changed

+685
-11
lines changed

.env.ci

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
1+
APP_NAME="TryPost"
12
APP_ENV=testing
23
APP_KEY=base64:Zfo+2dkSaHvem5LCiZS/baYHv2Pv1vrSc0F2NaF29Ec=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
SELF_HOSTED=true
8+
9+
APP_LOCALE=en
10+
APP_FALLBACK_LOCALE=en
11+
APP_FAKER_LOCALE=en_US
12+
13+
APP_MAINTENANCE_DRIVER=file
14+
15+
BCRYPT_ROUNDS=4
16+
17+
LOG_CHANNEL=stack
18+
LOG_STACK=single
19+
LOG_DEPRECATIONS_CHANNEL=null
20+
LOG_LEVEL=debug
21+
22+
# Database (PostgreSQL for CI)
23+
DB_CONNECTION=pgsql
24+
DB_HOST=127.0.0.1
25+
DB_PORT=5432
26+
DB_DATABASE=trypost_test
27+
DB_USERNAME=postgres
28+
DB_PASSWORD=password
29+
30+
# Session
31+
SESSION_DRIVER=array
32+
SESSION_LIFETIME=1440
33+
SESSION_ENCRYPT=false
34+
SESSION_PATH=/
35+
SESSION_DOMAIN=null
36+
37+
# Broadcasting, Queue, Cache
38+
BROADCAST_CONNECTION=null
39+
QUEUE_CONNECTION=sync
40+
CACHE_STORE=array
41+
42+
# File Storage
43+
FILESYSTEM_DISK=local
44+
45+
# Redis
46+
REDIS_HOST=127.0.0.1
47+
REDIS_PASSWORD=null
48+
REDIS_PORT=6379
49+
50+
# Mail
51+
MAIL_MAILER=array
52+
MAIL_HOST=127.0.0.1
53+
MAIL_PORT=2525
54+
MAIL_USERNAME=null
55+
MAIL_PASSWORD=null
56+
MAIL_ENCRYPTION=null
57+
MAIL_FROM_ADDRESS="[email protected]"
58+
MAIL_FROM_NAME="${APP_NAME}"
59+
60+
# Reverb (WebSockets) - disabled for testing
61+
REVERB_APP_ID=1001
62+
REVERB_APP_KEY=test-reverb-key
63+
REVERB_APP_SECRET=test-reverb-secret
64+
REVERB_HOST="localhost"
65+
REVERB_PORT=8080
66+
REVERB_SCHEME=http
67+
68+
# Disable optional services
69+
PULSE_ENABLED=false
70+
TELESCOPE_ENABLED=false
71+
NIGHTWATCH_ENABLED=false
72+
73+
# Vite
74+
VITE_APP_NAME="${APP_NAME}"
75+
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
76+
VITE_REVERB_HOST="${REVERB_HOST}"
77+
VITE_REVERB_PORT="${REVERB_PORT}"
78+
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

.github/workflows/tests.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,7 @@ jobs:
6969
run: npm run build
7070

7171
- name: Prepare environment
72-
run: |
73-
cp .env.example .env
74-
php artisan key:generate
75-
76-
- name: Configure test environment
77-
run: |
78-
sed -i 's/DB_DATABASE=trypost/DB_DATABASE=trypost_test/' .env
79-
sed -i 's/DB_PASSWORD=$/DB_PASSWORD=password/' .env
80-
sed -i 's/CACHE_STORE=redis/CACHE_STORE=array/' .env
81-
sed -i 's/QUEUE_CONNECTION=redis/QUEUE_CONNECTION=sync/' .env
82-
sed -i 's/SESSION_DRIVER=database/SESSION_DRIVER=array/' .env
72+
run: cp .env.ci .env
8373

8474
- name: Run migrations
8575
run: php artisan migrate --force

tests/Unit/Services/LinkedInPublisherTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Models\Workspace;
1010
use App\Services\Social\LinkedInPublisher;
1111
use Illuminate\Support\Facades\Http;
12+
use Illuminate\Support\Facades\Storage;
1213

1314
beforeEach(function () {
1415
$this->workspace = Workspace::factory()->create();
@@ -161,3 +162,58 @@
161162
expect(fn () => $publisher->publish($this->postPlatform))
162163
->toThrow(TokenExpiredException::class);
163164
});
165+
166+
test('linkedin publisher handles token refresh failure', function () {
167+
$this->socialAccount->update([
168+
'token_expires_at' => now()->subHour(),
169+
'refresh_token' => 'refresh-token-123',
170+
]);
171+
172+
Http::fake([
173+
'https://www.linkedin.com/oauth/v2/accessToken' => Http::response([
174+
'code' => 'INVALID_REFRESH_TOKEN',
175+
'message' => 'Invalid refresh token',
176+
], 400),
177+
]);
178+
179+
$publisher = new LinkedInPublisher;
180+
181+
expect(fn () => $publisher->publish($this->postPlatform))
182+
->toThrow(\Exception::class);
183+
});
184+
185+
test('linkedin publisher refreshes token when expiring soon', function () {
186+
$this->socialAccount->update([
187+
'token_expires_at' => now()->addMinutes(5),
188+
'refresh_token' => 'refresh-token-123',
189+
]);
190+
191+
Http::fake([
192+
'https://www.linkedin.com/oauth/v2/accessToken' => Http::response([
193+
'access_token' => 'new-access-token',
194+
'refresh_token' => 'new-refresh-token',
195+
'expires_in' => 3600,
196+
], 200),
197+
'*/rest/posts' => Http::response(null, 201, ['x-restli-id' => 'urn:li:share:123456']),
198+
]);
199+
200+
$publisher = new LinkedInPublisher;
201+
$result = $publisher->publish($this->postPlatform);
202+
203+
expect($result['id'])->toBe('urn:li:share:123456');
204+
$this->socialAccount->refresh();
205+
expect($this->socialAccount->access_token)->toBe('new-access-token');
206+
});
207+
208+
test('linkedin publisher handles empty post id header', function () {
209+
Http::fake([
210+
'*/rest/posts' => Http::response(null, 201),
211+
]);
212+
213+
$publisher = new LinkedInPublisher;
214+
$result = $publisher->publish($this->postPlatform);
215+
216+
// When header is empty, id will be empty string or 'unknown'
217+
expect($result)->toHaveKey('id');
218+
expect($result)->toHaveKey('url');
219+
});

0 commit comments

Comments
 (0)