mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-05-03 16:24:55 +00:00
🔥 **Cleanup:** Removed BookCase and OrangePill models, factories, migrations, and related references. Added tests for new service and meetup creation flows. Updated PHPUnit settings and browser-specific configurations.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Highscore;
|
||||
|
||||
it('returns all highscores ordered by satoshis desc on GET /api/highscores', function () {
|
||||
Highscore::factory()->create(['satoshis' => 100, 'achieved_at' => now()->subHours(1)]);
|
||||
Highscore::factory()->create(['satoshis' => 5000, 'achieved_at' => now()->subHours(2)]);
|
||||
Highscore::factory()->create(['satoshis' => 1000, 'achieved_at' => now()->subHours(3)]);
|
||||
|
||||
$response = $this->getJson('/api/highscores');
|
||||
|
||||
$response->assertSuccessful();
|
||||
$data = $response->json('data');
|
||||
expect(collect($data)->pluck('satoshis')->all())->toBe([5000, 1000, 100]);
|
||||
});
|
||||
|
||||
it('accepts a valid highscore submission', function () {
|
||||
$payload = [
|
||||
'npub' => 'npub1'.str_repeat('a', 58),
|
||||
'name' => 'Tester',
|
||||
'satoshis' => 1234,
|
||||
'blocks' => 5,
|
||||
'datetime' => now()->subDay()->toIso8601String(),
|
||||
];
|
||||
|
||||
$this->postJson('/api/highscores', $payload)
|
||||
->assertStatus(202)
|
||||
->assertJsonPath('data.satoshis', 1234)
|
||||
->assertJsonPath('data.name', 'Tester');
|
||||
|
||||
expect(Highscore::query()->where('npub', $payload['npub'])->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('rejects a highscore submission missing npub', function () {
|
||||
$this->postJson('/api/highscores', [
|
||||
'satoshis' => 1234,
|
||||
'blocks' => 5,
|
||||
'datetime' => now()->toIso8601String(),
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['npub']);
|
||||
});
|
||||
|
||||
it('rejects a highscore submission with an npub that does not start with npub1', function () {
|
||||
$this->postJson('/api/highscores', [
|
||||
'npub' => 'nsec1'.str_repeat('a', 58),
|
||||
'satoshis' => 1234,
|
||||
'blocks' => 5,
|
||||
'datetime' => now()->toIso8601String(),
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['npub']);
|
||||
});
|
||||
|
||||
it('rejects a highscore submission with negative satoshis', function () {
|
||||
$this->postJson('/api/highscores', [
|
||||
'npub' => 'npub1'.str_repeat('b', 58),
|
||||
'satoshis' => -10,
|
||||
'blocks' => 5,
|
||||
'datetime' => now()->toIso8601String(),
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['satoshis']);
|
||||
});
|
||||
|
||||
it('rejects a highscore submission with an invalid datetime', function () {
|
||||
$this->postJson('/api/highscores', [
|
||||
'npub' => 'npub1'.str_repeat('c', 58),
|
||||
'satoshis' => 100,
|
||||
'blocks' => 5,
|
||||
'datetime' => 'not-a-date',
|
||||
])->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['datetime']);
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use App\Models\User;
|
||||
|
||||
it('returns nostr-pubkeys in /api/nostrplebs', function () {
|
||||
User::factory()->create(['nostr' => 'npub1'.str_repeat('a', 58)]);
|
||||
User::factory()->create(['nostr' => 'npub1'.str_repeat('b', 58)]);
|
||||
User::factory()->create(['nostr' => null]);
|
||||
|
||||
$response = $this->getJson('/api/nostrplebs');
|
||||
|
||||
$response->assertSuccessful();
|
||||
expect($response->json())
|
||||
->toHaveCount(2)
|
||||
->each->toStartWith('npub1');
|
||||
});
|
||||
|
||||
it('returns bindle-type library items in /api/bindles', function () {
|
||||
LibraryItem::factory()->create(['type' => 'bindle', 'name' => 'My Bindle']);
|
||||
LibraryItem::factory()->create(['type' => 'article', 'name' => 'My Article']);
|
||||
|
||||
$response = $this->getJson('/api/bindles');
|
||||
|
||||
$response->assertSuccessful();
|
||||
$names = collect($response->json())->pluck('name');
|
||||
expect($names->all())
|
||||
->toContain('My Bindle')
|
||||
->not->toContain('My Article');
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Country;
|
||||
use App\Models\Meetup;
|
||||
use App\Models\MeetupEvent;
|
||||
|
||||
beforeEach(function () {
|
||||
$country = Country::factory()->create(['code' => 'de']);
|
||||
$this->city = City::factory()->create(['country_id' => $country->id]);
|
||||
});
|
||||
|
||||
it('returns visible meetups in JSON shape on GET /api/meetups', function () {
|
||||
Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'visible_on_map' => true,
|
||||
'name' => 'Visible Meetup',
|
||||
'community' => 'einundzwanzig',
|
||||
]);
|
||||
Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'visible_on_map' => false,
|
||||
'name' => 'Hidden Meetup',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/meetups');
|
||||
|
||||
$response->assertSuccessful();
|
||||
$names = collect($response->json())->pluck('name');
|
||||
expect($names->all())->toContain('Visible Meetup')
|
||||
->not->toContain('Hidden Meetup');
|
||||
});
|
||||
|
||||
it('includes intro and logo when ?withIntro=1&withLogos=1 is provided', function () {
|
||||
Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'visible_on_map' => true,
|
||||
'name' => 'WithExtras',
|
||||
'intro' => 'Some intro text',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/meetups?withIntro=1&withLogos=1');
|
||||
|
||||
$response->assertSuccessful();
|
||||
$payload = collect($response->json())->firstWhere('name', 'WithExtras');
|
||||
expect($payload)
|
||||
->intro->toBe('Some intro text')
|
||||
->logo->toBeString();
|
||||
});
|
||||
|
||||
it('returns einundzwanzig community meetups in BTC-Map format', function () {
|
||||
Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'community' => 'einundzwanzig',
|
||||
'name' => 'BTC Map Meetup',
|
||||
]);
|
||||
Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'community' => 'other',
|
||||
'name' => 'Excluded Meetup',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/btc-map-communities');
|
||||
|
||||
$response->assertSuccessful()
|
||||
->assertJsonStructure([['id', 'tags' => ['type', 'name']]]);
|
||||
|
||||
$names = collect($response->json())->pluck('tags.name');
|
||||
expect($names->all())
|
||||
->toContain('BTC Map Meetup')
|
||||
->not->toContain('Excluded Meetup');
|
||||
});
|
||||
|
||||
it('returns meetup events as JSON on GET /api/meetup-events', function () {
|
||||
$meetup = Meetup::factory()->create(['city_id' => $this->city->id]);
|
||||
MeetupEvent::factory()->create([
|
||||
'meetup_id' => $meetup->id,
|
||||
'start' => now()->addDay(),
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/meetup-events');
|
||||
|
||||
$response->assertSuccessful();
|
||||
expect($response->json())->toBeArray()->not->toBeEmpty();
|
||||
});
|
||||
|
||||
it('filters /api/meetup-events by date when one is supplied', function () {
|
||||
$meetup = Meetup::factory()->create(['city_id' => $this->city->id]);
|
||||
MeetupEvent::factory()->create(['meetup_id' => $meetup->id, 'start' => now()->addMonth()->startOfMonth()->addDays(5)]);
|
||||
|
||||
$date = now()->addMonth()->startOfMonth()->format('Y-m-d');
|
||||
$response = $this->getJson("/api/meetup-events/{$date}");
|
||||
|
||||
$response->assertSuccessful();
|
||||
expect($response->json())->toBeArray()->not->toBeEmpty();
|
||||
});
|
||||
Reference in New Issue
Block a user