Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
<?php
declare(strict_types=1);
use App\Actions\Changelog\ShowChangelogCard;
use App\Enums\Changelog\Reaction;
use App\Enums\Changelog\Tag;
use App\Models\ChangelogEntry;
use App\Models\ChangelogEntryView;
use App\Models\User;
use App\Models\Workspace;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Inertia\Testing\AssertableInertia;
beforeEach(function () {
config(['trypost.changelog.enabled' => true]);
$this->user = User::factory()->create(['created_at' => now()->subDays(30)]);
$workspace = Workspace::factory()->create([
'account_id' => $this->user->account_id,
'user_id' => $this->user->id,
]);
$workspace->members()->attach($this->user->id, membershipPivot('admin'));
$this->user->update(['current_workspace_id' => $workspace->id]);
subscribeAccount($this->user->account);
});
test('the card gets the newest entry while the user has not opened it', function () {
$newest = ChangelogEntry::factory()->create([
'published_on' => today(),
'title' => 'Newest entry',
'tags' => [Tag::New, Tag::Beta],
]);
ChangelogEntry::factory()->create(['published_on' => today()->subDay()]);
ChangelogEntry::factory()->create(['published_on' => today()->addDay()]);
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->where('changelog.latest.id', $newest->id)
->where('changelog.latest.title', 'Newest entry')
->where('changelog.latest.seen', false)
->where('changelog.latest.tags', [
['value' => 'new', 'label' => 'New'],
['value' => 'beta', 'label' => 'Beta'],
])
->missing('changelogEntries'));
});
test('the card is empty once the newest entry was opened, even with older ones unopened', function () {
$newest = ChangelogEntry::factory()->create(['published_on' => today()]);
ChangelogEntry::factory()->create(['published_on' => today()->subDay()]);
ChangelogEntryView::factory()->create(['changelog_entry_id' => $newest->id, 'user_id' => $this->user->id]);
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest', null));
});
test('the card is cached for ten minutes and cleared when the user opens the entry', function () {
$first = ChangelogEntry::factory()->create(['published_on' => today()->subDay()]);
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest.id', $first->id));
$newer = ChangelogEntry::factory()->create(['published_on' => today()]);
DB::enableQueryLog();
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest.id', $first->id));
expect(collect(DB::getQueryLog())->pluck('query')->filter(fn (string $query): bool => Str::contains($query, 'changelog_entries')))->toBeEmpty();
$this->actingAs($this->user->fresh())
->post(route('app.changelog.views.store', $newer))
->assertNoContent();
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest', null));
$newer->views()->delete();
$this->travel(11)->minutes();
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest.id', $newer->id));
});
test('reacting to the card entry before opening it also hides the card', function () {
$entry = ChangelogEntry::factory()->create(['published_on' => today()]);
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest.id', $entry->id));
$this->actingAs($this->user->fresh())
->putJson(route('app.changelog.reaction.update', $entry), ['reaction' => 'like'])
->assertNoContent();
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest', null));
});
test('the card works with a cache store that serializes its values', function () {
config(['cache.stores.array.serialize' => true]);
Cache::forgetDriver('array');
$entry = ChangelogEntry::factory()->create(['published_on' => today(), 'body' => 'Some <b>bold</b> **news** here.']);
foreach ([1, 2] as $visit) {
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->where('changelog.latest.id', $entry->id)
->where('changelog.latest.published_on', today()->toDateString())
->where('changelog.latest.excerpt', 'Some bold news here.')
->where('changelog.latest.body_html', "<p>Some bold <strong>news</strong> here.</p>\n"));
}
});
test('a sync that changes the entries refreshes every cached card at once', function () {
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest', null));
$newest = ChangelogEntry::factory()->create(['published_on' => today()]);
ShowChangelogCard::forgetAll();
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest.id', $newest->id));
});
test('a user who signed up today never gets an older entry on the card', function () {
$this->user->forceFill(['created_at' => now()])->save();
ChangelogEntry::factory()->create(['published_on' => today()->subDay()]);
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page->where('changelog.latest', null));
});
test('nothing is shared when the changelog is turned off', function () {
config(['trypost.changelog.enabled' => false]);
ChangelogEntry::factory()->create();
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page
->where('changelog', null)
->missing('changelogEntries'));
});
test('guests get no changelog data', function () {
ChangelogEntry::factory()->create();
$this->get(route('login'))
->assertOk()
->assertInertia(fn (AssertableInertia $page) => $page
->missing('changelog')
->missing('changelogEntries'));
});
test('the modal list loads every published entry, five per page, newest first, with whether the user opened and liked each one', function () {
$this->user->forceFill(['created_at' => now()->subDays(2)])->save();
$entries = collect(range(0, 6))->map(fn (int $daysAgo) => ChangelogEntry::factory()->create([
'published_on' => today()->subDays($daysAgo),
]));
ChangelogEntry::factory()->create(['published_on' => today()->addDay()]);
ChangelogEntryView::factory()->create([
'changelog_entry_id' => $entries[1]->id,
'user_id' => $this->user->id,
'reaction' => Reaction::Like,
]);
ChangelogEntryView::factory()->create(['changelog_entry_id' => $entries[1]->id, 'reaction' => Reaction::Dislike]);
$this->actingAs($this->user->fresh())
->get(route('app.calendar'))
->assertInertia(fn (AssertableInertia $page) => $page
->reloadOnly('changelogEntries', fn (AssertableInertia $reload) => $reload
->has('changelogEntries.data', 5)
->where('changelogEntries.data.0.id', $entries[0]->id)
->where('changelogEntries.data.1.seen', true)
->where('changelogEntries.data.0.seen', false)
->where('changelogEntries.data.1.reaction', 'like')
->where('changelogEntries.data.0.reaction', null)));
$this->actingAs($this->user->fresh())
->get(route('app.calendar', ['changelog_page' => 2]))
->assertInertia(fn (AssertableInertia $page) => $page
->reloadOnly('changelogEntries', fn (AssertableInertia $reload) => $reload
->has('changelogEntries.data', 2)
->where('changelogEntries.data.1.id', $entries[6]->id)));
});