Compare commits
17 commits
c7b9cd6d0c
...
ced6cfcaac
| Author | SHA1 | Date | |
|---|---|---|---|
| ced6cfcaac | |||
| 1b95e9f8aa | |||
| 3c86b0637e | |||
| 0bfe8180bb | |||
| f7982edafe | |||
| 8e9ca0e200 | |||
| 4e3f83142e | |||
| 812c663529 | |||
| 90ecad22a7 | |||
| 6485cabdae | |||
| 2b87f1f3a7 | |||
| 6270c97c29 | |||
| dc64dd83b8 | |||
| eefadff873 | |||
| d58fd8a231 | |||
| dd8f799445 | |||
| d8b85f84ed |
56 changed files with 11062 additions and 869 deletions
|
|
@ -38,7 +38,7 @@ jobs:
|
||||||
run: vendor/bin/pint --test
|
run: vendor/bin/pint --test
|
||||||
|
|
||||||
- name: Static analysis
|
- name: Static analysis
|
||||||
run: vendor/bin/phpstan analyse
|
run: vendor/bin/phpstan analyse --memory-limit=1G
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: php artisan test --coverage-clover coverage.xml --coverage-text
|
run: php artisan test --coverage-clover coverage.xml --coverage-text
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -19,7 +19,6 @@ npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
/auth.json
|
/auth.json
|
||||||
/composer.lock
|
|
||||||
/.idea
|
/.idea
|
||||||
/coverage-report*
|
/coverage-report*
|
||||||
/coverage.xml
|
/coverage.xml
|
||||||
|
|
|
||||||
38
CHANGELOG.md
Normal file
38
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [1.4.0] - UNRELEASED
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add a dark theme (#88)
|
||||||
|
- Add a daily publish cap, so a feed returning a large batch cannot flood a community (#90)
|
||||||
|
- Defaults to unlimited, so existing installs publish exactly as before until someone opts in.
|
||||||
|
- Add an in-app activity log showing what the automation has been doing (#91)
|
||||||
|
- Add a scheduled platform credential health check (#95)
|
||||||
|
- Add a warning for feeds that fetch successfully but return no articles (#116)
|
||||||
|
- Add community existence validation when creating a channel (#114)
|
||||||
|
- Add edit and delete actions to feed and channel cards (#136, #137, #141)
|
||||||
|
- Deleting a channel cascades to its routes, keywords, route articles and publications, so past days in the dashboard charts lose those data points.
|
||||||
|
- Add a Failed tab surfacing publishes that did not go through (#142)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix a failed publish disappearing from the interface instead of returning to the user (#142)
|
||||||
|
- Automatic retry is removed, replaced by a per-row Retry action.
|
||||||
|
- Fix modals being unusable by keyboard (#111)
|
||||||
|
- Fix oversized thumbnails (#138)
|
||||||
|
- Fix renamed Tailwind v4 utilities rendering at a shifted scale (#109)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Rework the dashboard with trends and breakdowns over a selectable date range (#83)
|
||||||
|
- Make an article's routing legible on the Articles page, with per-feed colour, grouping and a filter (#113)
|
||||||
|
- Store an article's thumbnail when it is fetched rather than re-fetching the page on every publish (#119)
|
||||||
|
- Replace the stock Laravel branding with the project's own (#121)
|
||||||
|
- Extract business logic from services into Action classes (#144)
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Remove the unused Inertia, Ziggy and Breeze dependencies, the dead Jenkinsfile, and the Inertia middleware (#140)
|
||||||
95
CONTRIBUTING.md
Normal file
95
CONTRIBUTING.md
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Thanks for your interest in FFR. This is a small self-hosted project, issues and
|
||||||
|
pull requests are both welcome.
|
||||||
|
|
||||||
|
## Reporting issues
|
||||||
|
|
||||||
|
Use [Issues](https://forge.lvl0.xyz/lvl0/fedi-feed-router/issues).
|
||||||
|
|
||||||
|
For bugs, include what you expected, what happened, and enough detail to
|
||||||
|
reproduce it. If a feed is behaving unexpectedly, the feed URL matters most
|
||||||
|
because differences in how providers structure their RSS or Atom output are the
|
||||||
|
usual cause. Relevant log output helps; `dev-logs` follows the application log.
|
||||||
|
|
||||||
|
## Development setup
|
||||||
|
|
||||||
|
Requires PHP 8.2+ and Docker. The development environment runs in containers
|
||||||
|
defined by `docker/dev/docker-compose.yml`.
|
||||||
|
|
||||||
|
On NixOS, or anywhere with Nix installed:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://forge.lvl0.xyz/lvl0/fedi-feed-router.git
|
||||||
|
cd fedi-feed-router
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
|
The shell prints the available commands on entry and can start the containers
|
||||||
|
for you:
|
||||||
|
|
||||||
|
| Command | Description |
|
||||||
|
|---------|-------------|
|
||||||
|
| `dev-up` | Start the development environment |
|
||||||
|
| `dev-down` | Stop the development environment |
|
||||||
|
| `dev-restart` | Restart the containers |
|
||||||
|
| `dev-rebuild` | Rebuild the images |
|
||||||
|
| `dev-shell` | Enter the app container |
|
||||||
|
| `dev-artisan <cmd>` | Run an artisan command |
|
||||||
|
| `dev-logs` | Follow the application log |
|
||||||
|
| `dev-logs-db` | Follow the database log |
|
||||||
|
|
||||||
|
Once running:
|
||||||
|
|
||||||
|
| Service | URL |
|
||||||
|
|---------|-----|
|
||||||
|
| App | http://localhost:8000 |
|
||||||
|
| Vite | http://localhost:5173 |
|
||||||
|
| MariaDB | localhost:3307 |
|
||||||
|
| Redis | localhost:6380 |
|
||||||
|
|
||||||
|
Without Nix, start the same containers directly from
|
||||||
|
`docker/dev/docker-compose.yml`. Contributions improving the setup instructions
|
||||||
|
for other platforms are welcome.
|
||||||
|
|
||||||
|
## Before opening a pull request
|
||||||
|
|
||||||
|
Three checks run in CI, and all three must pass. Run them locally first, from
|
||||||
|
inside the app container or anywhere the project's dependencies are available:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vendor/bin/pint --test # code style, Laravel preset
|
||||||
|
vendor/bin/phpstan analyse # static analysis, level 7
|
||||||
|
php artisan test # PHPUnit, Unit and Feature suites
|
||||||
|
```
|
||||||
|
|
||||||
|
Some conventions:
|
||||||
|
|
||||||
|
- **Static analysis.** PHPStan runs at level 7 with a baseline
|
||||||
|
(`phpstan-baseline.neon`) covering pre-existing findings. Don't add baseline
|
||||||
|
entries to silence errors in code you're writing. Fix the cause instead.
|
||||||
|
Inline `@phpstan-ignore` comments aren't used in this project. The baseline is
|
||||||
|
for cases where the analyser or an upstream docblock is wrong, not real bugs.
|
||||||
|
- **Tests.** New behaviour needs a test. Tests must run offline, so use fixtures
|
||||||
|
or fakes rather than reaching for the network.
|
||||||
|
- **Dependencies.** `composer.lock` is committed. If you change dependencies,
|
||||||
|
commit the updated lockfile alongside `composer.json`.
|
||||||
|
|
||||||
|
## Commits
|
||||||
|
|
||||||
|
One commit does one thing. Keep each commit passing all three checks so history
|
||||||
|
stays bisectable. Separate renames from behaviour changes, and mechanical edits
|
||||||
|
from logic.
|
||||||
|
|
||||||
|
Commit messages are a single line, referencing the issue they belong to:
|
||||||
|
|
||||||
|
```
|
||||||
|
141 - Add channel deletion to the Channels page
|
||||||
|
```
|
||||||
|
|
||||||
|
No body, no trailers.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
By contributing, you agree that your contributions are licensed under the
|
||||||
|
[GNU AGPL-3.0](LICENSE), the same license as the project.
|
||||||
241
Jenkinsfile
vendored
241
Jenkinsfile
vendored
|
|
@ -1,241 +0,0 @@
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
|
|
||||||
environment {
|
|
||||||
APP_ENV = 'testing'
|
|
||||||
DB_CONNECTION = 'mysql'
|
|
||||||
DB_HOST = 'mysql'
|
|
||||||
DB_PORT = '3306'
|
|
||||||
DB_DATABASE = 'ffr_testing'
|
|
||||||
DB_USERNAME = 'ffr_user'
|
|
||||||
DB_PASSWORD = 'ffr_password'
|
|
||||||
CACHE_STORE = 'array'
|
|
||||||
SESSION_DRIVER = 'array'
|
|
||||||
QUEUE_CONNECTION = 'sync'
|
|
||||||
}
|
|
||||||
|
|
||||||
stages {
|
|
||||||
stage('Checkout') {
|
|
||||||
steps {
|
|
||||||
checkout scm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Setup Environment') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
sh '''
|
|
||||||
echo "Setting up environment for testing..."
|
|
||||||
cp .env.example .env.testing
|
|
||||||
echo "APP_ENV=testing" >> .env.testing
|
|
||||||
echo "DB_CONNECTION=${DB_CONNECTION}" >> .env.testing
|
|
||||||
echo "DB_HOST=${DB_HOST}" >> .env.testing
|
|
||||||
echo "DB_PORT=${DB_PORT}" >> .env.testing
|
|
||||||
echo "DB_DATABASE=${DB_DATABASE}" >> .env.testing
|
|
||||||
echo "DB_USERNAME=${DB_USERNAME}" >> .env.testing
|
|
||||||
echo "DB_PASSWORD=${DB_PASSWORD}" >> .env.testing
|
|
||||||
echo "CACHE_STORE=${CACHE_STORE}" >> .env.testing
|
|
||||||
echo "SESSION_DRIVER=${SESSION_DRIVER}" >> .env.testing
|
|
||||||
echo "QUEUE_CONNECTION=${QUEUE_CONNECTION}" >> .env.testing
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Install Dependencies') {
|
|
||||||
parallel {
|
|
||||||
stage('PHP Dependencies') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Installing PHP dependencies..."
|
|
||||||
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Node Dependencies') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Installing Node.js dependencies..."
|
|
||||||
npm ci
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Generate Application Key') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
php artisan key:generate --env=testing --force
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Database Setup') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Setting up test database..."
|
|
||||||
php artisan migrate:fresh --env=testing --force
|
|
||||||
php artisan config:clear --env=testing
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Code Quality Checks') {
|
|
||||||
parallel {
|
|
||||||
stage('PHP Syntax Check') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Checking PHP syntax..."
|
|
||||||
find . -name "*.php" -not -path "./vendor/*" -not -path "./node_modules/*" -exec php -l {} \\;
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('PHPStan Analysis') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
try {
|
|
||||||
sh '''
|
|
||||||
if [ -f "phpstan.neon" ]; then
|
|
||||||
echo "Running PHPStan static analysis..."
|
|
||||||
./vendor/bin/phpstan analyse --no-progress --error-format=table
|
|
||||||
else
|
|
||||||
echo "PHPStan configuration not found, skipping static analysis"
|
|
||||||
fi
|
|
||||||
'''
|
|
||||||
} catch (Exception e) {
|
|
||||||
unstable(message: "PHPStan found issues")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Security Audit') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
try {
|
|
||||||
sh '''
|
|
||||||
echo "Running security audit..."
|
|
||||||
composer audit
|
|
||||||
'''
|
|
||||||
} catch (Exception e) {
|
|
||||||
unstable(message: "Security vulnerabilities found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Unit Tests') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Running Unit Tests..."
|
|
||||||
php artisan test tests/Unit/ --env=testing --stop-on-failure
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
publishTestResults testResultsPattern: 'tests/Unit/results/*.xml'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Feature Tests') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Running Feature Tests..."
|
|
||||||
php artisan test tests/Feature/ --env=testing --stop-on-failure
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
publishTestResults testResultsPattern: 'tests/Feature/results/*.xml'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Full Regression Test Suite') {
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Running comprehensive regression test suite..."
|
|
||||||
chmod +x ./run-regression-tests.sh
|
|
||||||
./run-regression-tests.sh
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
// Archive test results
|
|
||||||
archiveArtifacts artifacts: 'tests/reports/**/*', allowEmptyArchive: true
|
|
||||||
|
|
||||||
// Publish coverage reports if available
|
|
||||||
publishHTML([
|
|
||||||
allowMissing: false,
|
|
||||||
alwaysLinkToLastBuild: true,
|
|
||||||
keepAll: true,
|
|
||||||
reportDir: 'coverage',
|
|
||||||
reportFiles: 'index.html',
|
|
||||||
reportName: 'Coverage Report'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Performance Tests') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
try {
|
|
||||||
sh '''
|
|
||||||
echo "Running performance tests..."
|
|
||||||
|
|
||||||
# Test memory usage
|
|
||||||
php -d memory_limit=256M artisan test tests/Feature/DatabaseIntegrationTest.php --env=testing
|
|
||||||
|
|
||||||
# Test response times for API endpoints
|
|
||||||
time php artisan test tests/Feature/ApiEndpointRegressionTest.php --env=testing
|
|
||||||
'''
|
|
||||||
} catch (Exception e) {
|
|
||||||
unstable(message: "Performance tests indicated potential issues")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build Assets') {
|
|
||||||
when {
|
|
||||||
anyOf {
|
|
||||||
branch 'main'
|
|
||||||
branch 'develop'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
sh '''
|
|
||||||
echo "Building production assets..."
|
|
||||||
npm run build
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
// Clean up
|
|
||||||
sh '''
|
|
||||||
echo "Cleaning up..."
|
|
||||||
rm -f .env.testing
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
success {
|
|
||||||
echo '✅ All regression tests passed successfully!'
|
|
||||||
// Notify success (customize as needed)
|
|
||||||
// slackSend channel: '#dev-team', color: 'good', message: "Regression tests passed for ${env.JOB_NAME} - ${env.BUILD_NUMBER}"
|
|
||||||
}
|
|
||||||
failure {
|
|
||||||
echo '❌ Regression tests failed!'
|
|
||||||
// Notify failure (customize as needed)
|
|
||||||
// slackSend channel: '#dev-team', color: 'danger', message: "Regression tests failed for ${env.JOB_NAME} - ${env.BUILD_NUMBER}"
|
|
||||||
}
|
|
||||||
unstable {
|
|
||||||
echo '⚠️ Tests completed with warnings'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
661
LICENSE
Normal file
661
LICENSE
Normal file
|
|
@ -0,0 +1,661 @@
|
||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
138
README.md
138
README.md
|
|
@ -1,26 +1,77 @@
|
||||||
# FFR (Feed to Fediverse Router)
|
# FFR: Feed to Fediverse Router
|
||||||
|
|
||||||
A Laravel-based application for routing RSS/Atom feeds to Fediverse platforms like Lemmy. Built with Laravel, Livewire, and FrankenPHP for a modern, single-container deployment.
|
[](https://forge.lvl0.xyz/lvl0/fedi-feed-router/actions)
|
||||||
|
[](https://forge.lvl0.xyz/lvl0/fedi-feed-router/releases)
|
||||||
|
[](LICENSE)
|
||||||
|
|
||||||
|
Routes news articles to Fediverse communities. FFR polls a set of sources,
|
||||||
|
extracts each article, and posts it to the Lemmy communities you map it to,
|
||||||
|
either automatically or after you approve it.
|
||||||
|
|
||||||
|
It is meant to run unattended on your own server: point it at a source, map that
|
||||||
|
source to a community, and let it publish on a schedule you control.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The dashboard, showing article volume over a selected range, approval and publish
|
||||||
|
success rates, and per-feed breakdowns.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The review queue. Each row is one feed and community pairing, grouped by feed,
|
||||||
|
with the routing shown above the headline.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Feed aggregation** - Fetch articles from multiple RSS/Atom feeds
|
- **Article routing**: map each source to one or more Lemmy communities, with
|
||||||
- **Fediverse publishing** - Automatically post to Lemmy communities
|
optional keyword filtering
|
||||||
- **Route configuration** - Map feeds to specific channels with keywords
|
- **Approval workflow**: review articles before they publish, or let them go out
|
||||||
- **Approval workflow** - Optional manual approval before publishing
|
automatically
|
||||||
- **Queue processing** - Background job handling with Laravel Horizon
|
- **Publishing controls**: a global interval and an optional daily cap, so a
|
||||||
- **Single container deployment** - Simplified hosting with FrankenPHP
|
source returning a large batch cannot flood a community
|
||||||
|
- **Dashboard**: articles fetched and published over time, approval and publish
|
||||||
|
success rates, and per-source and per-community breakdowns
|
||||||
|
- **Activity log**: a chronological record of what the automation has done
|
||||||
|
- **Health checks**: warnings for sources that stop producing articles and for
|
||||||
|
platform credentials that stop working
|
||||||
|
- **Dark theme**
|
||||||
|
- **Single container**: FrankenPHP serves the app, with MariaDB and Redis
|
||||||
|
alongside
|
||||||
|
|
||||||
|
## Sources and platforms
|
||||||
|
|
||||||
|
FFR ships with parsers for three sources:
|
||||||
|
|
||||||
|
| Source | Type |
|
||||||
|
|--------|------|
|
||||||
|
| VRT News | Website |
|
||||||
|
| Belga | Website |
|
||||||
|
| The Guardian | RSS |
|
||||||
|
|
||||||
|
Some sources publish a usable feed and some do not, so a source is either read
|
||||||
|
from RSS or scraped from its pages. Either way a parser handles it, registered
|
||||||
|
in `config/feed.php`.
|
||||||
|
|
||||||
|
Adding a source means implementing `ArticleParserInterface` (three methods:
|
||||||
|
`canParse`, `extractData`, `getSourceName`) and registering it. See
|
||||||
|
[CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
|
Lemmy is currently the only supported platform.
|
||||||
|
|
||||||
## Self-hosting
|
## Self-hosting
|
||||||
|
|
||||||
The production image is available at `forge.lvl0.xyz/lvl0/fedi-feed-router:latest`.
|
Images are published to `forge.lvl0.xyz/lvl0/fedi-feed-router`. The example below
|
||||||
|
pins a release tag; check [Releases](https://forge.lvl0.xyz/lvl0/fedi-feed-router/releases)
|
||||||
|
for the current one, and the [CHANGELOG](CHANGELOG.md) before upgrading.
|
||||||
|
|
||||||
### docker-compose.yml
|
### docker-compose.yml
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: forge.lvl0.xyz/lvl0/fedi-feed-router:latest
|
image: forge.lvl0.xyz/lvl0/fedi-feed-router:v1.4.0
|
||||||
container_name: ffr_app
|
container_name: ffr_app
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
|
|
@ -70,42 +121,59 @@ ### docker-compose.yml
|
||||||
app_storage:
|
app_storage:
|
||||||
```
|
```
|
||||||
|
|
||||||
### Environment Variables
|
### Environment variables
|
||||||
|
|
||||||
| Variable | Required | Description |
|
| Variable | Required | Description |
|
||||||
|----------|----------|-------------|
|
|----------|----------|-------------|
|
||||||
| `APP_KEY` | Yes | Encryption key. Generate with: `echo "base64:$(openssl rand -base64 32)"` |
|
| `APP_KEY` | Yes | Encryption key. Generate with: `echo "base64:$(openssl rand -base64 32)"` |
|
||||||
| `APP_URL` | Yes | Your domain (e.g., `https://ffr.example.com`) |
|
| `APP_URL` | Yes | Your domain (e.g. `https://ffr.example.com`) |
|
||||||
| `DB_DATABASE` | Yes | Database name |
|
| `DB_DATABASE` | Yes | Database name |
|
||||||
| `DB_USERNAME` | Yes | Database user |
|
| `DB_USERNAME` | Yes | Database user |
|
||||||
| `DB_PASSWORD` | Yes | Database password |
|
| `DB_PASSWORD` | Yes | Database password |
|
||||||
| `DB_ROOT_PASSWORD` | Yes | MariaDB root password |
|
| `DB_ROOT_PASSWORD` | Yes | MariaDB root password |
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
On first run FFR walks you through onboarding. After that:
|
||||||
|
|
||||||
|
1. **Add a channel** on the Channels page. A channel is a Lemmy community on a
|
||||||
|
given instance, together with the account that posts to it. The community is
|
||||||
|
picked from the instance, so a typo cannot create a channel that fails later.
|
||||||
|
2. **Add a feed** on the Feeds page, choosing one of the supported sources.
|
||||||
|
3. **Add a route** on the Routes page, mapping a feed to a channel. Keywords on a
|
||||||
|
route restrict it to articles that match.
|
||||||
|
|
||||||
|
Articles are then discovered on a schedule. Each one becomes a row per matching
|
||||||
|
route, so an article routed to three communities is three separate decisions.
|
||||||
|
Approve one on the Articles page and it publishes to that route's community;
|
||||||
|
publishing failures come back to you on the Failed tab rather than retrying
|
||||||
|
silently.
|
||||||
|
|
||||||
|
Publishing runs every five minutes, one article per run, bounded by the daily cap
|
||||||
|
if you set one.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### NixOS / Nix
|
### NixOS / Nix
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://forge.lvl0.xyz/lvl0/fedi-feed-router.git
|
git clone https://forge.lvl0.xyz/lvl0/fedi-feed-router.git
|
||||||
cd ffr
|
cd fedi-feed-router
|
||||||
nix-shell
|
nix-shell
|
||||||
```
|
```
|
||||||
|
|
||||||
The shell will display available commands and optionally start the containers for you.
|
The shell prints the available commands and can start the containers for you.
|
||||||
|
|
||||||
#### Available Commands
|
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| `dev-up` | Start development environment |
|
| `dev-up` | Start the development environment |
|
||||||
| `dev-down` | Stop development environment |
|
| `dev-down` | Stop the development environment |
|
||||||
| `dev-restart` | Restart containers |
|
| `dev-restart` | Restart the containers |
|
||||||
| `dev-logs` | Follow app logs |
|
| `dev-rebuild` | Rebuild the images |
|
||||||
| `dev-logs-db` | Follow database logs |
|
| `dev-shell` | Enter the app container |
|
||||||
| `dev-shell` | Enter app container |
|
| `dev-artisan <cmd>` | Run an artisan command |
|
||||||
| `dev-artisan <cmd>` | Run artisan commands |
|
| `dev-logs` | Follow the application log |
|
||||||
|
| `dev-logs-db` | Follow the database log |
|
||||||
#### Services
|
|
||||||
|
|
||||||
| Service | URL |
|
| Service | URL |
|
||||||
|---------|-----|
|
|---------|-----|
|
||||||
|
|
@ -114,14 +182,22 @@ #### Services
|
||||||
| MariaDB | localhost:3307 |
|
| MariaDB | localhost:3307 |
|
||||||
| Redis | localhost:6380 |
|
| Redis | localhost:6380 |
|
||||||
|
|
||||||
### Other Platforms
|
### Other platforms
|
||||||
|
|
||||||
Contributions welcome for development setup instructions on other platforms.
|
Contributions welcome for development setup instructions on other platforms.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for
|
||||||
|
the development setup, the checks that run in CI, and the commit conventions.
|
||||||
|
|
||||||
|
For bugs and questions, use
|
||||||
|
[Issues](https://forge.lvl0.xyz/lvl0/fedi-feed-router/issues).
|
||||||
|
|
||||||
|
## Note on AI assistance
|
||||||
|
|
||||||
|
This project was developed with AI assistance.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is open-source software licensed under the [AGPL-3.0 license](LICENSE).
|
FFR is free software, licensed under the [GNU AGPL-3.0](LICENSE).
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
For issues and questions, please use [Issues](https://forge.lvl0.xyz/lvl0/fedi-feed-router/issues).
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Article;
|
namespace App\Actions;
|
||||||
|
|
||||||
use App\Enums\ApprovalStatusEnum;
|
use App\Enums\ApprovalStatusEnum;
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
|
|
@ -10,48 +10,9 @@
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class ValidationService
|
class CreateRouteArticlesAction
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function execute(Article $article, string $content): void
|
||||||
private ArticleFetcher $articleFetcher
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function validate(Article $article): Article
|
|
||||||
{
|
|
||||||
logger('Validating article for routes: '.$article->id);
|
|
||||||
|
|
||||||
$articleData = $this->articleFetcher->fetchArticleData($article);
|
|
||||||
|
|
||||||
$updateData = [];
|
|
||||||
|
|
||||||
if (! empty($articleData)) {
|
|
||||||
$updateData['title'] = $articleData['title'] ?? $article->title;
|
|
||||||
$updateData['description'] = $articleData['description'] ?? $article->description;
|
|
||||||
$updateData['content'] = $articleData['full_article'] ?? null;
|
|
||||||
$updateData['image_url'] = ($articleData['thumbnail'] ?? null) ?: $article->image_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! isset($articleData['full_article']) || empty($articleData['full_article'])) {
|
|
||||||
logger()->warning('Article data missing full_article content', [
|
|
||||||
'article_id' => $article->id,
|
|
||||||
'url' => $article->url,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$updateData['validated_at'] = now();
|
|
||||||
$article->update($updateData);
|
|
||||||
|
|
||||||
return $article->refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
$updateData['validated_at'] = now();
|
|
||||||
$article->update($updateData);
|
|
||||||
|
|
||||||
$this->createRouteArticles($article, $articleData['full_article']);
|
|
||||||
|
|
||||||
return $article->refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createRouteArticles(Article $article, string $content): void
|
|
||||||
{
|
{
|
||||||
$activeRoutes = Route::where('feed_id', $article->feed_id)
|
$activeRoutes = Route::where('feed_id', $article->feed_id)
|
||||||
->where('is_active', true)
|
->where('is_active', true)
|
||||||
36
app/Actions/FetchArticleDataAction.php
Normal file
36
app/Actions/FetchArticleDataAction.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Services\Factories\ArticleParserFactory;
|
||||||
|
use App\Services\Http\HttpFetcher;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class FetchArticleDataAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private LogSaver $logSaver
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function execute(Article $article): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$html = HttpFetcher::fetchHtml($article->url);
|
||||||
|
$parser = ArticleParserFactory::getParser($article->url);
|
||||||
|
|
||||||
|
return $parser->extractData($html);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->logSaver->error('Exception while fetching article data', null, [
|
||||||
|
'url' => $article->url,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
app/Actions/FetchFeedArticlesAction.php
Normal file
36
app/Actions/FetchFeedArticlesAction.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class FetchFeedArticlesAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private LogSaver $logSaver,
|
||||||
|
private FetchRssArticlesAction $fetchRssArticles,
|
||||||
|
private FetchWebsiteArticlesAction $fetchWebsiteArticles,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Article>
|
||||||
|
*/
|
||||||
|
public function execute(Feed $feed): Collection
|
||||||
|
{
|
||||||
|
if ($feed->type === 'rss') {
|
||||||
|
return $this->fetchRssArticles->execute($feed);
|
||||||
|
} elseif ($feed->type === 'website') {
|
||||||
|
return $this->fetchWebsiteArticles->execute($feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logSaver->warning('Unsupported feed type', null, [
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'feed_type' => $feed->type,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
64
app/Actions/FetchRssArticlesAction.php
Normal file
64
app/Actions/FetchRssArticlesAction.php
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Services\Http\HttpFetcher;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class FetchRssArticlesAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private LogSaver $logSaver,
|
||||||
|
private SaveArticleAction $saveArticle,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Article>
|
||||||
|
*/
|
||||||
|
public function execute(Feed $feed): Collection
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$xml = HttpFetcher::fetchHtml($feed->url);
|
||||||
|
|
||||||
|
$previousUseErrors = libxml_use_internal_errors(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$rss = simplexml_load_string($xml);
|
||||||
|
} finally {
|
||||||
|
libxml_clear_errors();
|
||||||
|
libxml_use_internal_errors($previousUseErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rss === false || ! isset($rss->channel->item)) {
|
||||||
|
$this->logSaver->warning('Failed to parse RSS feed XML', null, [
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'feed_url' => $feed->url,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$articles = collect();
|
||||||
|
foreach ($rss->channel->item as $item) {
|
||||||
|
$link = (string) $item->link;
|
||||||
|
if ($link !== '') {
|
||||||
|
$articles->push($this->saveArticle->execute($link, $feed->id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $articles;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->logSaver->error('Failed to fetch articles from RSS feed', null, [
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'feed_url' => $feed->url,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
app/Actions/FetchWebsiteArticlesAction.php
Normal file
53
app/Actions/FetchWebsiteArticlesAction.php
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Services\Factories\HomepageParserFactory;
|
||||||
|
use App\Services\Http\HttpFetcher;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class FetchWebsiteArticlesAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private LogSaver $logSaver,
|
||||||
|
private SaveArticleAction $saveArticle,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Article>
|
||||||
|
*/
|
||||||
|
public function execute(Feed $feed): Collection
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$parser = HomepageParserFactory::getParserForFeed($feed);
|
||||||
|
|
||||||
|
if (! $parser) {
|
||||||
|
$this->logSaver->warning('No parser available for feed URL', null, [
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'feed_url' => $feed->url,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = HttpFetcher::fetchHtml($feed->url);
|
||||||
|
$urls = $parser->extractArticleUrls($html);
|
||||||
|
|
||||||
|
return collect($urls)
|
||||||
|
->map(fn (string $url) => $this->saveArticle->execute($url, $feed->id));
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->logSaver->error('Failed to fetch articles from website feed', null, [
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'feed_url' => $feed->url,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
use App\Exceptions\PublishException;
|
use App\Exceptions\PublishException;
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use App\Services\Publishing\ArticlePublishingService;
|
use App\Services\Publishing\ArticlePublishingService;
|
||||||
use App\Services\Publishing\PublishOutcome;
|
use App\Services\Publishing\PublishOutcome;
|
||||||
|
|
@ -21,7 +20,7 @@
|
||||||
class PublishRouteArticleAction
|
class PublishRouteArticleAction
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ArticleFetcher $articleFetcher,
|
private FetchArticleDataAction $fetchArticleData,
|
||||||
private ArticlePublishingService $publishingService,
|
private ArticlePublishingService $publishingService,
|
||||||
private NotificationService $notificationService,
|
private NotificationService $notificationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
@ -90,7 +89,7 @@ private function hasPublishableContent(array $extractedData): bool
|
||||||
private function resolvePublishData(Article $article): array
|
private function resolvePublishData(Article $article): array
|
||||||
{
|
{
|
||||||
if (empty($article->description) && empty($article->image_url)) {
|
if (empty($article->description) && empty($article->image_url)) {
|
||||||
return $this->articleFetcher->fetchArticleData($article);
|
return $this->fetchArticleData->execute($article);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
52
app/Actions/SaveArticleAction.php
Normal file
52
app/Actions/SaveArticleAction.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class SaveArticleAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private LogSaver $logSaver
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function execute(string $url, ?int $feedId = null): Article
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$article = Article::firstOrCreate(
|
||||||
|
['url' => $url],
|
||||||
|
[
|
||||||
|
'feed_id' => $feedId,
|
||||||
|
'title' => $this->generateFallbackTitle($url),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($article->wasRecentlyCreated) {
|
||||||
|
$article->dispatchFetchedEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $article;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->logSaver->error('Failed to create article', null, [
|
||||||
|
'url' => $url,
|
||||||
|
'feed_id' => $feedId,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateFallbackTitle(string $url): string
|
||||||
|
{
|
||||||
|
$path = parse_url($url, PHP_URL_PATH);
|
||||||
|
$filename = basename($path ?: $url);
|
||||||
|
|
||||||
|
$title = preg_replace('/\.[^.]*$/', '', $filename);
|
||||||
|
$title = str_replace(['-', '_'], ' ', $title);
|
||||||
|
$title = ucwords($title);
|
||||||
|
|
||||||
|
return $title ?: 'Untitled Article';
|
||||||
|
}
|
||||||
|
}
|
||||||
48
app/Actions/ValidateArticleAction.php
Normal file
48
app/Actions/ValidateArticleAction.php
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
|
||||||
|
class ValidateArticleAction
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private FetchArticleDataAction $fetchArticleData,
|
||||||
|
private CreateRouteArticlesAction $createRouteArticles,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function execute(Article $article): Article
|
||||||
|
{
|
||||||
|
logger('Validating article for routes: '.$article->id);
|
||||||
|
|
||||||
|
$articleData = $this->fetchArticleData->execute($article);
|
||||||
|
|
||||||
|
$updateData = [];
|
||||||
|
|
||||||
|
if (! empty($articleData)) {
|
||||||
|
$updateData['title'] = $articleData['title'] ?? $article->title;
|
||||||
|
$updateData['description'] = $articleData['description'] ?? $article->description;
|
||||||
|
$updateData['content'] = $articleData['full_article'] ?? null;
|
||||||
|
$updateData['image_url'] = ($articleData['thumbnail'] ?? null) ?: $article->image_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($articleData['full_article']) || empty($articleData['full_article'])) {
|
||||||
|
logger()->warning('Article data missing full_article content', [
|
||||||
|
'article_id' => $article->id,
|
||||||
|
'url' => $article->url,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$updateData['validated_at'] = now();
|
||||||
|
$article->update($updateData);
|
||||||
|
|
||||||
|
return $article->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateData['validated_at'] = now();
|
||||||
|
$article->update($updateData);
|
||||||
|
|
||||||
|
$this->createRouteArticles->execute($article, $articleData['full_article']);
|
||||||
|
|
||||||
|
return $article->refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Inertia\Middleware;
|
|
||||||
|
|
||||||
class HandleInertiaRequests extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The root template that's loaded on the first page visit.
|
|
||||||
*
|
|
||||||
* @see https://inertiajs.com/server-side-setup#root-template
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $rootView = 'app';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the current asset version.
|
|
||||||
*
|
|
||||||
* @see https://inertiajs.com/asset-versioning
|
|
||||||
*/
|
|
||||||
public function version(Request $request): ?string
|
|
||||||
{
|
|
||||||
return parent::version($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the props that are shared by default.
|
|
||||||
*
|
|
||||||
* @see https://inertiajs.com/shared-data
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function share(Request $request): array
|
|
||||||
{
|
|
||||||
return array_merge(parent::share($request), [
|
|
||||||
//
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Actions\FetchFeedArticlesAction;
|
||||||
use App\Enums\ActivityTypeEnum;
|
use App\Enums\ActivityTypeEnum;
|
||||||
use App\Enums\NotificationSeverityEnum;
|
use App\Enums\NotificationSeverityEnum;
|
||||||
use App\Enums\NotificationTypeEnum;
|
use App\Enums\NotificationTypeEnum;
|
||||||
use App\Events\ActivityLogged;
|
use App\Events\ActivityLogged;
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Models\Notification;
|
use App\Models\Notification;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
use App\Services\Log\LogSaver;
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
@ -26,7 +26,7 @@ public function __construct(
|
||||||
$this->onQueue('feed-discovery');
|
$this->onQueue('feed-discovery');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher, NotificationService $notificationService): void
|
public function handle(LogSaver $logSaver, FetchFeedArticlesAction $fetchFeedArticles, NotificationService $notificationService): void
|
||||||
{
|
{
|
||||||
$logSaver->info('Starting feed article fetch', null, [
|
$logSaver->info('Starting feed article fetch', null, [
|
||||||
'feed_id' => $this->feed->id,
|
'feed_id' => $this->feed->id,
|
||||||
|
|
@ -34,7 +34,7 @@ public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher, Notif
|
||||||
'feed_url' => $this->feed->url,
|
'feed_url' => $this->feed->url,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articles = $articleFetcher->getArticlesFromFeed($this->feed);
|
$articles = $fetchFeedArticles->execute($this->feed);
|
||||||
|
|
||||||
$logSaver->info('Feed article fetch completed', null, [
|
$logSaver->info('Feed article fetch completed', null, [
|
||||||
'feed_id' => $this->feed->id,
|
'feed_id' => $this->feed->id,
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace App\Listeners;
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\Actions\ValidateArticleAction;
|
||||||
use App\Enums\ActivityTypeEnum;
|
use App\Enums\ActivityTypeEnum;
|
||||||
use App\Enums\LogLevelEnum;
|
use App\Enums\LogLevelEnum;
|
||||||
use App\Events\ActionPerformed;
|
use App\Events\ActionPerformed;
|
||||||
use App\Events\ActivityLogged;
|
use App\Events\ActivityLogged;
|
||||||
use App\Events\NewArticleFetched;
|
use App\Events\NewArticleFetched;
|
||||||
use App\Services\Article\ValidationService;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ class ValidateArticleListener implements ShouldQueue
|
||||||
public string $queue = 'default';
|
public string $queue = 'default';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ValidationService $validationService
|
private ValidateArticleAction $validateArticle
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function handle(NewArticleFetched $event): void
|
public function handle(NewArticleFetched $event): void
|
||||||
|
|
@ -33,7 +33,7 @@ public function handle(NewArticleFetched $event): void
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
ActivityLogged::dispatch(
|
ActivityLogged::dispatch(
|
||||||
ActivityTypeEnum::VALIDATE,
|
ActivityTypeEnum::VALIDATE,
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,14 @@
|
||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
use App\Actions\CreateChannelAction;
|
use App\Actions\CreateChannelAction;
|
||||||
|
use App\Enums\LogLevelEnum;
|
||||||
|
use App\Events\ActionPerformed;
|
||||||
|
use App\Models\ArticlePublication;
|
||||||
use App\Models\Language;
|
use App\Models\Language;
|
||||||
use App\Models\PlatformAccount;
|
use App\Models\PlatformAccount;
|
||||||
use App\Models\PlatformChannel;
|
use App\Models\PlatformChannel;
|
||||||
use App\Models\PlatformInstance;
|
use App\Models\PlatformInstance;
|
||||||
|
use App\Models\RouteArticle;
|
||||||
use App\Services\Platform\CommunityDirectory;
|
use App\Services\Platform\CommunityDirectory;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
|
|
@ -49,6 +53,34 @@ public function toggle(int $channelId): void
|
||||||
$channel->save();
|
$channel->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteChannel(int $channelId): void
|
||||||
|
{
|
||||||
|
$channel = PlatformChannel::find($channelId);
|
||||||
|
|
||||||
|
if (! $channel instanceof PlatformChannel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $channel->display_name;
|
||||||
|
|
||||||
|
// Routes, keywords, route articles, publications, account links and synced posts
|
||||||
|
// all cascade at the database level.
|
||||||
|
$channel->delete();
|
||||||
|
|
||||||
|
if ($this->managingChannelId === $channelId) {
|
||||||
|
$this->managingChannelId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->editingChannelId === $channelId) {
|
||||||
|
$this->editingChannelId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionPerformed::dispatch('Deleted platform channel', LogLevelEnum::WARNING, [
|
||||||
|
'platform_channel_id' => $channelId,
|
||||||
|
'display_name' => $name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function openCreateModal(): void
|
public function openCreateModal(): void
|
||||||
{
|
{
|
||||||
$this->reset(['newCommunityId', 'newPlatformInstanceId', 'newLanguageId', 'newDescription', 'availableCommunities', 'communityLoadError']);
|
$this->reset(['newCommunityId', 'newPlatformInstanceId', 'newLanguageId', 'newDescription', 'availableCommunities', 'communityLoadError']);
|
||||||
|
|
@ -208,6 +240,39 @@ public function detachAccount(int $channelId, int $accountId): void
|
||||||
$channel->platformAccounts()->detach($accountId);
|
$channel->platformAccounts()->detach($accountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row counts per channel, so the delete confirmation can say what is about to go.
|
||||||
|
*
|
||||||
|
* @return array<int, array{articles: int, publications: int}>
|
||||||
|
*/
|
||||||
|
private function deletionImpact(): array
|
||||||
|
{
|
||||||
|
/** @var array<int, int> $articles */
|
||||||
|
$articles = RouteArticle::query()
|
||||||
|
->selectRaw('platform_channel_id, COUNT(*) as aggregate')
|
||||||
|
->groupBy('platform_channel_id')
|
||||||
|
->pluck('aggregate', 'platform_channel_id')
|
||||||
|
->all();
|
||||||
|
|
||||||
|
/** @var array<int, int> $publications */
|
||||||
|
$publications = ArticlePublication::query()
|
||||||
|
->selectRaw('platform_channel_id, COUNT(*) as aggregate')
|
||||||
|
->groupBy('platform_channel_id')
|
||||||
|
->pluck('aggregate', 'platform_channel_id')
|
||||||
|
->all();
|
||||||
|
|
||||||
|
$impact = [];
|
||||||
|
|
||||||
|
foreach (array_keys($articles + $publications) as $channelId) {
|
||||||
|
$impact[$channelId] = [
|
||||||
|
'articles' => (int) ($articles[$channelId] ?? 0),
|
||||||
|
'publications' => (int) ($publications[$channelId] ?? 0),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $impact;
|
||||||
|
}
|
||||||
|
|
||||||
public function render(): View
|
public function render(): View
|
||||||
{
|
{
|
||||||
$channels = PlatformChannel::with(['platformInstance', 'platformAccounts'])->orderBy('name')->get();
|
$channels = PlatformChannel::with(['platformInstance', 'platformAccounts'])->orderBy('name')->get();
|
||||||
|
|
@ -228,6 +293,7 @@ public function render(): View
|
||||||
? PlatformChannel::with('platformInstance')->find($this->editingChannelId)
|
? PlatformChannel::with('platformInstance')->find($this->editingChannelId)
|
||||||
: null,
|
: null,
|
||||||
'availableAccounts' => $availableAccounts,
|
'availableAccounts' => $availableAccounts,
|
||||||
|
'deletionImpact' => $this->deletionImpact(),
|
||||||
'platformInstances' => PlatformInstance::where('is_active', true)->orderBy('name')->get(),
|
'platformInstances' => PlatformInstance::where('is_active', true)->orderBy('name')->get(),
|
||||||
'languages' => Language::where('is_active', true)->orderBy('name')->get(),
|
'languages' => Language::where('is_active', true)->orderBy('name')->get(),
|
||||||
])->layout('layouts.app');
|
])->layout('layouts.app');
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
* @method static create(array<string, mixed> $array)
|
* @method static create(array<string, mixed> $array)
|
||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property int $feed_id
|
* @property int|null $feed_id
|
||||||
* @property Feed $feed
|
* @property Feed $feed
|
||||||
* @property string $url
|
* @property string $url
|
||||||
* @property string $title
|
* @property string $title
|
||||||
|
|
|
||||||
|
|
@ -1,181 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Article;
|
|
||||||
|
|
||||||
use App\Models\Article;
|
|
||||||
use App\Models\Feed;
|
|
||||||
use App\Services\Factories\ArticleParserFactory;
|
|
||||||
use App\Services\Factories\HomepageParserFactory;
|
|
||||||
use App\Services\Http\HttpFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
class ArticleFetcher
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private LogSaver $logSaver
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, Article>
|
|
||||||
*/
|
|
||||||
public function getArticlesFromFeed(Feed $feed): Collection
|
|
||||||
{
|
|
||||||
if ($feed->type === 'rss') {
|
|
||||||
return $this->getArticlesFromRssFeed($feed);
|
|
||||||
} elseif ($feed->type === 'website') {
|
|
||||||
return $this->getArticlesFromWebsiteFeed($feed);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->logSaver->warning('Unsupported feed type', null, [
|
|
||||||
'feed_id' => $feed->id,
|
|
||||||
'feed_type' => $feed->type,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, Article>
|
|
||||||
*/
|
|
||||||
private function getArticlesFromRssFeed(Feed $feed): Collection
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$xml = HttpFetcher::fetchHtml($feed->url);
|
|
||||||
|
|
||||||
$previousUseErrors = libxml_use_internal_errors(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$rss = simplexml_load_string($xml);
|
|
||||||
} finally {
|
|
||||||
libxml_clear_errors();
|
|
||||||
libxml_use_internal_errors($previousUseErrors);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($rss === false || ! isset($rss->channel->item)) {
|
|
||||||
$this->logSaver->warning('Failed to parse RSS feed XML', null, [
|
|
||||||
'feed_id' => $feed->id,
|
|
||||||
'feed_url' => $feed->url,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
$articles = collect();
|
|
||||||
foreach ($rss->channel->item as $item) {
|
|
||||||
$link = (string) $item->link;
|
|
||||||
if ($link !== '') {
|
|
||||||
$articles->push($this->saveArticle($link, $feed->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $articles;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logSaver->error('Failed to fetch articles from RSS feed', null, [
|
|
||||||
'feed_id' => $feed->id,
|
|
||||||
'feed_url' => $feed->url,
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return collect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, Article>
|
|
||||||
*/
|
|
||||||
private function getArticlesFromWebsiteFeed(Feed $feed): Collection
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
// Try to get parser for this feed
|
|
||||||
$parser = HomepageParserFactory::getParserForFeed($feed);
|
|
||||||
|
|
||||||
if (! $parser) {
|
|
||||||
$this->logSaver->warning('No parser available for feed URL', null, [
|
|
||||||
'feed_id' => $feed->id,
|
|
||||||
'feed_url' => $feed->url,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
$html = HttpFetcher::fetchHtml($feed->url);
|
|
||||||
$urls = $parser->extractArticleUrls($html);
|
|
||||||
|
|
||||||
return collect($urls)
|
|
||||||
->map(fn (string $url) => $this->saveArticle($url, $feed->id));
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logSaver->error('Failed to fetch articles from website feed', null, [
|
|
||||||
'feed_id' => $feed->id,
|
|
||||||
'feed_url' => $feed->url,
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return collect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function fetchArticleData(Article $article): array
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$html = HttpFetcher::fetchHtml($article->url);
|
|
||||||
$parser = ArticleParserFactory::getParser($article->url);
|
|
||||||
|
|
||||||
return $parser->extractData($html);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logSaver->error('Exception while fetching article data', null, [
|
|
||||||
'url' => $article->url,
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveArticle(string $url, ?int $feedId = null): Article
|
|
||||||
{
|
|
||||||
$fallbackTitle = $this->generateFallbackTitle($url);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$article = Article::firstOrCreate(
|
|
||||||
['url' => $url],
|
|
||||||
[
|
|
||||||
'feed_id' => $feedId,
|
|
||||||
'title' => $fallbackTitle,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($article->wasRecentlyCreated) {
|
|
||||||
$article->dispatchFetchedEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $article;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logSaver->error('Failed to create article', null, [
|
|
||||||
'url' => $url,
|
|
||||||
'feed_id' => $feedId,
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateFallbackTitle(string $url): string
|
|
||||||
{
|
|
||||||
// Extract filename from URL as a basic fallback title
|
|
||||||
$path = parse_url($url, PHP_URL_PATH);
|
|
||||||
$filename = basename($path ?: $url);
|
|
||||||
|
|
||||||
// Remove file extension and convert to readable format
|
|
||||||
$title = preg_replace('/\.[^.]*$/', '', $filename);
|
|
||||||
$title = str_replace(['-', '_'], ' ', $title);
|
|
||||||
$title = ucwords($title);
|
|
||||||
|
|
||||||
return $title ?: 'Untitled Article';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +1,35 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://getcomposer.org/schema.json",
|
"$schema": "https://getcomposer.org/schema.json",
|
||||||
"name": "laravel/react-starter-kit",
|
"name": "lvl0/fedi-feed-router",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"description": "The skeleton application for the Laravel framework.",
|
"description": "Routes news articles from RSS and scraped sources to Fediverse communities.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"laravel",
|
"fediverse",
|
||||||
"framework"
|
"lemmy",
|
||||||
|
"rss",
|
||||||
|
"atom",
|
||||||
|
"laravel"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"homepage": "https://forge.lvl0.xyz/lvl0/fedi-feed-router",
|
||||||
|
"license": "AGPL-3.0-only",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
"blade-ui-kit/blade-heroicons": "^2.6",
|
"blade-ui-kit/blade-heroicons": "^2.6",
|
||||||
"inertiajs/inertia-laravel": "^2.0",
|
|
||||||
"laravel/framework": "^12.0",
|
"laravel/framework": "^12.0",
|
||||||
"laravel/horizon": "^5.29",
|
"laravel/horizon": "^5.29",
|
||||||
"laravel/sanctum": "^4.2",
|
"laravel/sanctum": "^4.2",
|
||||||
"laravel/tinker": "^2.10.1",
|
"laravel/tinker": "^2.10.1",
|
||||||
"livewire/livewire": "^4.0",
|
"livewire/livewire": "^4.0"
|
||||||
"tightenco/ziggy": "^2.4"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
"larastan/larastan": "^3.5",
|
"larastan/larastan": "^3.5",
|
||||||
"laravel/breeze": "^2.3",
|
|
||||||
"laravel/pail": "^1.2.2",
|
"laravel/pail": "^1.2.2",
|
||||||
"laravel/pint": "^1.18",
|
"laravel/pint": "^1.18",
|
||||||
"laravel/sail": "^1.43",
|
"laravel/sail": "^1.43",
|
||||||
"mockery/mockery": "^1.6",
|
"mockery/mockery": "^1.6",
|
||||||
"nunomaduro/collision": "^8.6",
|
"nunomaduro/collision": "^8.6",
|
||||||
"phpstan/phpstan": "^2.1",
|
"phpstan/phpstan": "^2.1.32 <2.2",
|
||||||
"phpstan/phpstan-mockery": "^2.0",
|
"phpstan/phpstan-mockery": "^2.0",
|
||||||
"phpunit/phpunit": "^11.5.3"
|
"phpunit/phpunit": "^11.5.3"
|
||||||
},
|
},
|
||||||
|
|
@ -64,11 +65,6 @@
|
||||||
"Composer\\Config::disableProcessTimeout",
|
"Composer\\Config::disableProcessTimeout",
|
||||||
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
|
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
|
||||||
],
|
],
|
||||||
"dev:ssr": [
|
|
||||||
"npm run build:ssr",
|
|
||||||
"Composer\\Config::disableProcessTimeout",
|
|
||||||
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"php artisan inertia:start-ssr\" --names=server,queue,logs,ssr --kill-others"
|
|
||||||
],
|
|
||||||
"test": [
|
"test": [
|
||||||
"@php artisan config:clear --ansi",
|
"@php artisan config:clear --ansi",
|
||||||
"@php artisan test"
|
"@php artisan test"
|
||||||
|
|
|
||||||
8754
composer.lock
generated
Normal file
8754
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// The column never had a constraint, so pre-existing rows may point at deleted channels.
|
||||||
|
$orphans = DB::table('article_publications')
|
||||||
|
->whereNotIn('platform_channel_id', DB::table('platform_channels')->select('id'));
|
||||||
|
|
||||||
|
if (($count = $orphans->count()) > 0) {
|
||||||
|
Log::warning("Deleting {$count} orphaned article_publications rows before adding the channel foreign key.");
|
||||||
|
$orphans->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
Schema::table('article_publications', function (Blueprint $table) {
|
||||||
|
$table->foreign('platform_channel_id')
|
||||||
|
->references('id')
|
||||||
|
->on('platform_channels')
|
||||||
|
->onDelete('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Orphan rows deleted in up() are not restored.
|
||||||
|
Schema::table('article_publications', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['platform_channel_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
BIN
docs/screenshots/articles-light.png
Normal file
BIN
docs/screenshots/articles-light.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 672 KiB |
BIN
docs/screenshots/channels-dark.png
Normal file
BIN
docs/screenshots/channels-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 350 KiB |
BIN
docs/screenshots/dashboard-dark.png
Normal file
BIN
docs/screenshots/dashboard-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 663 KiB |
BIN
docs/screenshots/feeds-dark.png
Normal file
BIN
docs/screenshots/feeds-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 269 KiB |
BIN
docs/screenshots/routes-edit-dark.png
Normal file
BIN
docs/screenshots/routes-edit-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 372 KiB |
|
|
@ -1,5 +1,11 @@
|
||||||
parameters:
|
parameters:
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
|
-
|
||||||
|
message: '#^Instanceof between Illuminate\\Http\\Client\\Response and Exception will always evaluate to false\.$#'
|
||||||
|
identifier: instanceof.alwaysFalse
|
||||||
|
count: 1
|
||||||
|
path: app/Services/Http/HttpFetcher.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: '#^Call to an undefined static method App\\Models\\Feed\:\:withTrashed\(\)\.$#'
|
message: '#^Call to an undefined static method App\\Models\\Feed\:\:withTrashed\(\)\.$#'
|
||||||
identifier: staticMethod.notFound
|
identifier: staticMethod.notFound
|
||||||
|
|
@ -108,8 +114,3 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: tests/Unit/Models/RouteTest.php
|
path: tests/Unit/Models/RouteTest.php
|
||||||
|
|
||||||
-
|
|
||||||
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertNull\(\) with int will always evaluate to false\.$#'
|
|
||||||
identifier: method.impossibleType
|
|
||||||
count: 1
|
|
||||||
path: tests/Unit/Services/ArticleFetcherTest.php
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,19 @@ class="p-1 rounded-full {{ $channel->is_active ? 'bg-green-100 text-green-600 da
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" />
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@php($impact = $deletionImpact[$channel->id] ?? ['articles' => 0, 'publications' => 0])
|
||||||
|
<button
|
||||||
|
wire:click="deleteChannel({{ $channel->id }})"
|
||||||
|
wire:confirm="Delete "{{ $channel->display_name }}"? This also removes its routes, {{ $impact['articles'] }} article{{ $impact['articles'] === 1 ? '' : 's' }} routed to it and {{ $impact['publications'] }} publication record{{ $impact['publications'] === 1 ? '' : 's' }}. This cannot be undone."
|
||||||
|
class="p-1 rounded-full text-gray-400 hover:bg-red-50 hover:text-red-600 dark:text-gray-500 dark:hover:bg-red-900/20 dark:hover:text-red-400"
|
||||||
|
title="Delete channel"
|
||||||
|
aria-label="Delete {{ $channel->display_name }}"
|
||||||
|
>
|
||||||
|
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
Route::fallback(function () {
|
Route::fallback(function () {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'This is the FFR API backend. Use /api/v1/* endpoints or check the React frontend.',
|
'message' => 'Not found. The FFR interface is at /dashboard; API endpoints are under /api/v1.',
|
||||||
'api_base' => '/api/v1',
|
'api_base' => '/api/v1',
|
||||||
], 404);
|
], 404);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public function test_fallback_route_returns_api_message(): void
|
||||||
$response = $this->get('/nonexistent-route');
|
$response = $this->get('/nonexistent-route');
|
||||||
$response->assertStatus(404);
|
$response->assertStatus(404);
|
||||||
$response->assertJson([
|
$response->assertJson([
|
||||||
'message' => 'This is the FFR API backend. Use /api/v1/* endpoints or check the React frontend.',
|
'message' => 'Not found. The FFR interface is at /dashboard; API endpoints are under /api/v1.',
|
||||||
'api_base' => '/api/v1',
|
'api_base' => '/api/v1',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
120
tests/Feature/ChannelDeletionCascadeTest.php
Normal file
120
tests/Feature/ChannelDeletionCascadeTest.php
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\ArticlePublication;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Models\Keyword;
|
||||||
|
use App\Models\PlatformAccount;
|
||||||
|
use App\Models\PlatformChannel;
|
||||||
|
use App\Models\Route;
|
||||||
|
use App\Models\RouteArticle;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ChannelDeletionCascadeTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{PlatformChannel, Feed}
|
||||||
|
*/
|
||||||
|
private function channelWithEverything(): array
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
/** @var PlatformChannel $channel */
|
||||||
|
$channel = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
Route::create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
'priority' => 50,
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Keyword::create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
'keyword' => 'brussels',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
|
|
||||||
|
RouteArticle::factory()->create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
'article_id' => $article->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ArticlePublication::factory()->create([
|
||||||
|
'article_id' => $article->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$account = PlatformAccount::factory()->create();
|
||||||
|
$channel->platformAccounts()->attach($account->id, [
|
||||||
|
'is_active' => true,
|
||||||
|
'priority' => 1,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [$channel, $feed];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_a_channel_cascades_to_every_dependent_table(): void
|
||||||
|
{
|
||||||
|
[$channel] = $this->channelWithEverything();
|
||||||
|
|
||||||
|
$this->assertSame(1, Route::count());
|
||||||
|
$this->assertSame(1, Keyword::count());
|
||||||
|
$this->assertSame(1, RouteArticle::count());
|
||||||
|
$this->assertSame(1, ArticlePublication::count());
|
||||||
|
|
||||||
|
$channel->delete();
|
||||||
|
|
||||||
|
$this->assertSame(0, Route::count());
|
||||||
|
$this->assertSame(0, Keyword::count());
|
||||||
|
$this->assertSame(0, RouteArticle::count());
|
||||||
|
$this->assertSame(0, ArticlePublication::count());
|
||||||
|
$this->assertDatabaseCount('platform_account_channels', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_a_channel_leaves_the_feed_and_article_intact(): void
|
||||||
|
{
|
||||||
|
[$channel, $feed] = $this->channelWithEverything();
|
||||||
|
|
||||||
|
$channel->delete();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('feeds', ['id' => $feed->id]);
|
||||||
|
$this->assertSame(1, Article::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_a_channel_leaves_other_channels_untouched(): void
|
||||||
|
{
|
||||||
|
[$channel] = $this->channelWithEverything();
|
||||||
|
$other = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
$channel->delete();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('platform_channels', ['id' => $other->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_publications_for_another_channel_survive(): void
|
||||||
|
{
|
||||||
|
[$channel] = $this->channelWithEverything();
|
||||||
|
|
||||||
|
$other = PlatformChannel::factory()->create();
|
||||||
|
$article = Article::factory()->create();
|
||||||
|
ArticlePublication::factory()->create([
|
||||||
|
'article_id' => $article->id,
|
||||||
|
'platform_channel_id' => $other->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$channel->delete();
|
||||||
|
|
||||||
|
$this->assertSame(1, ArticlePublication::count());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
use App\Actions\PublishRouteArticleAction;
|
use App\Actions\PublishRouteArticleAction;
|
||||||
use App\Enums\PublishStatusEnum;
|
use App\Enums\PublishStatusEnum;
|
||||||
use App\Events\RouteArticleApproved;
|
use App\Events\RouteArticleApproved;
|
||||||
|
|
@ -15,7 +16,6 @@
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Modules\Lemmy\Services\LemmyPublisher;
|
use App\Modules\Lemmy\Services\LemmyPublisher;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
use App\Services\Log\LogSaver;
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use App\Services\Publishing\ArticlePublishingService;
|
use App\Services\Publishing\ArticlePublishingService;
|
||||||
|
|
@ -93,8 +93,8 @@ private function makeListener(): PublishApprovedArticleListener
|
||||||
$service->shouldAllowMockingProtectedMethods();
|
$service->shouldAllowMockingProtectedMethods();
|
||||||
$service->shouldReceive('makePublisher')->andReturn($publisher);
|
$service->shouldReceive('makePublisher')->andReturn($publisher);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
return new PublishApprovedArticleListener(new PublishRouteArticleAction($fetcher, $service, new NotificationService));
|
return new PublishApprovedArticleListener(new PublishRouteArticleAction($fetcher, $service, new NotificationService));
|
||||||
}
|
}
|
||||||
|
|
@ -159,8 +159,8 @@ public function test_two_queued_listeners_create_only_one_remote_post(): void
|
||||||
$service->shouldAllowMockingProtectedMethods();
|
$service->shouldAllowMockingProtectedMethods();
|
||||||
$service->shouldReceive('makePublisher')->andReturn($publisher);
|
$service->shouldReceive('makePublisher')->andReturn($publisher);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$listener = new PublishApprovedArticleListener(new PublishRouteArticleAction($fetcher, $service, new NotificationService));
|
$listener = new PublishApprovedArticleListener(new PublishRouteArticleAction($fetcher, $service, new NotificationService));
|
||||||
$listener->handle(new RouteArticleApproved($routeArticle));
|
$listener->handle(new RouteArticleApproved($routeArticle));
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Jobs;
|
namespace Tests\Feature\Jobs;
|
||||||
|
|
||||||
|
use App\Actions\FetchFeedArticlesAction;
|
||||||
use App\Enums\ActivityTypeEnum;
|
use App\Enums\ActivityTypeEnum;
|
||||||
use App\Enums\NotificationSeverityEnum;
|
use App\Enums\NotificationSeverityEnum;
|
||||||
use App\Enums\NotificationTypeEnum;
|
use App\Enums\NotificationTypeEnum;
|
||||||
|
|
@ -10,7 +11,6 @@
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Models\Notification;
|
use App\Models\Notification;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
use App\Services\Log\LogSaver;
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
@ -27,8 +27,8 @@ class ArticleDiscoveryForFeedJobEmptyFetchTest extends TestCase
|
||||||
*/
|
*/
|
||||||
private function runJobForFeed(Feed $feed, ?Collection $articles = null): void
|
private function runJobForFeed(Feed $feed, ?Collection $articles = null): void
|
||||||
{
|
{
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchFeedArticlesAction::class);
|
||||||
$fetcher->shouldReceive('getArticlesFromFeed')
|
$fetcher->shouldReceive('execute')
|
||||||
->andReturn($articles ?? collect());
|
->andReturn($articles ?? collect());
|
||||||
|
|
||||||
(new ArticleDiscoveryForFeedJob($feed))->handle(
|
(new ArticleDiscoveryForFeedJob($feed))->handle(
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
|
use App\Actions\FetchFeedArticlesAction;
|
||||||
use App\Enums\ApprovalStatusEnum;
|
use App\Enums\ApprovalStatusEnum;
|
||||||
use App\Enums\LogLevelEnum;
|
use App\Enums\LogLevelEnum;
|
||||||
use App\Events\ActionPerformed;
|
use App\Events\ActionPerformed;
|
||||||
|
|
@ -23,7 +25,6 @@
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
use App\Services\Log\LogSaver;
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
@ -63,18 +64,18 @@ public function test_article_discovery_for_feed_job_processes_feed(): void
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Mock the ArticleFetcher service in the container
|
// Mock the feed fetch in the container
|
||||||
$mockFetcher = \Mockery::mock(ArticleFetcher::class);
|
$mockFetcher = \Mockery::mock(FetchFeedArticlesAction::class);
|
||||||
$article1 = Article::factory()->create(['url' => 'https://example.com/article1', 'feed_id' => $feed->id]);
|
$article1 = Article::factory()->create(['url' => 'https://example.com/article1', 'feed_id' => $feed->id]);
|
||||||
$article2 = Article::factory()->create(['url' => 'https://example.com/article2', 'feed_id' => $feed->id]);
|
$article2 = Article::factory()->create(['url' => 'https://example.com/article2', 'feed_id' => $feed->id]);
|
||||||
$mockFetcher->shouldReceive('getArticlesFromFeed')
|
$mockFetcher->shouldReceive('execute')
|
||||||
->with($feed)
|
->with($feed)
|
||||||
->andReturn(collect([$article1, $article2]));
|
->andReturn(collect([$article1, $article2]));
|
||||||
|
|
||||||
$this->app->instance(ArticleFetcher::class, $mockFetcher);
|
$this->app->instance(FetchFeedArticlesAction::class, $mockFetcher);
|
||||||
|
|
||||||
$logSaver = app(LogSaver::class);
|
$logSaver = app(LogSaver::class);
|
||||||
$articleFetcher = app(ArticleFetcher::class);
|
$articleFetcher = app(FetchFeedArticlesAction::class);
|
||||||
$job = new ArticleDiscoveryForFeedJob($feed);
|
$job = new ArticleDiscoveryForFeedJob($feed);
|
||||||
$job->handle($logSaver, $articleFetcher, app(NotificationService::class));
|
$job->handle($logSaver, $articleFetcher, app(NotificationService::class));
|
||||||
|
|
||||||
|
|
@ -167,10 +168,10 @@ public function test_validate_article_listener_processes_new_article(): void
|
||||||
'feed_id' => $feed->id,
|
'feed_id' => $feed->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Mock ArticleFetcher to return valid article data
|
// Mock the article-data fetch to return valid data
|
||||||
$mockFetcher = \Mockery::mock(ArticleFetcher::class);
|
$mockFetcher = \Mockery::mock(FetchArticleDataAction::class);
|
||||||
$this->app->instance(ArticleFetcher::class, $mockFetcher);
|
$this->app->instance(FetchArticleDataAction::class, $mockFetcher);
|
||||||
$mockFetcher->shouldReceive('fetchArticleData')
|
$mockFetcher->shouldReceive('execute')
|
||||||
->with($article)
|
->with($article)
|
||||||
->andReturn([
|
->andReturn([
|
||||||
'title' => 'Belgian News',
|
'title' => 'Belgian News',
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Listeners;
|
namespace Tests\Feature\Listeners;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
use App\Actions\PublishRouteArticleAction;
|
use App\Actions\PublishRouteArticleAction;
|
||||||
use App\Enums\NotificationSeverityEnum;
|
use App\Enums\NotificationSeverityEnum;
|
||||||
use App\Enums\NotificationTypeEnum;
|
use App\Enums\NotificationTypeEnum;
|
||||||
|
|
@ -13,7 +14,6 @@
|
||||||
use App\Models\Notification;
|
use App\Models\Notification;
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use App\Services\Publishing\ArticlePublishingService;
|
use App\Services\Publishing\ArticlePublishingService;
|
||||||
use App\Services\Publishing\PublishOutcome;
|
use App\Services\Publishing\PublishOutcome;
|
||||||
|
|
@ -48,8 +48,8 @@ public function test_exception_during_publishing_creates_error_notification(): v
|
||||||
{
|
{
|
||||||
$routeArticle = $this->createApprovedRouteArticle();
|
$routeArticle = $this->createApprovedRouteArticle();
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andThrow(new Exception('Connection refused'));
|
->andThrow(new Exception('Connection refused'));
|
||||||
|
|
||||||
|
|
@ -76,8 +76,8 @@ public function test_no_publication_created_creates_warning_notification(): void
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -106,8 +106,8 @@ public function test_successful_publish_does_not_create_notification(): void
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -131,8 +131,8 @@ public function test_skips_already_published_to_channel(): void
|
||||||
'platform_channel_id' => $routeArticle->platform_channel_id,
|
'platform_channel_id' => $routeArticle->platform_channel_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldNotReceive('fetchArticleData');
|
$articleFetcherMock->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,14 @@
|
||||||
namespace Tests\Feature\Livewire;
|
namespace Tests\Feature\Livewire;
|
||||||
|
|
||||||
use App\Livewire\Channels;
|
use App\Livewire\Channels;
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\ArticlePublication;
|
||||||
|
use App\Models\Feed;
|
||||||
use App\Models\Language;
|
use App\Models\Language;
|
||||||
use App\Models\PlatformAccount;
|
use App\Models\PlatformAccount;
|
||||||
use App\Models\PlatformChannel;
|
use App\Models\PlatformChannel;
|
||||||
use App\Models\PlatformInstance;
|
use App\Models\PlatformInstance;
|
||||||
|
use App\Models\RouteArticle;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Http\Client\Factory;
|
use Illuminate\Http\Client\Factory;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
@ -410,4 +414,124 @@ public function test_update_channel_does_nothing_without_an_open_modal(): void
|
||||||
|
|
||||||
$this->assertSame('Original', $channel->fresh()->display_name);
|
$this->assertSame('Original', $channel->fresh()->display_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_channel_cards_show_a_delete_action(): void
|
||||||
|
{
|
||||||
|
PlatformChannel::factory()->create(['display_name' => 'Tech Community']);
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->assertSee('Delete Tech Community');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_a_channel_removes_it(): void
|
||||||
|
{
|
||||||
|
$channel = PlatformChannel::factory()->create();
|
||||||
|
$survivor = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)->call('deleteChannel', $channel->id);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('platform_channels', ['id' => $channel->id]);
|
||||||
|
$this->assertDatabaseHas('platform_channels', ['id' => $survivor->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_an_unknown_channel_does_nothing(): void
|
||||||
|
{
|
||||||
|
PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->call('deleteChannel', 999999)
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$this->assertSame(1, PlatformChannel::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_the_channel_being_edited_closes_the_edit_modal(): void
|
||||||
|
{
|
||||||
|
$channel = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->call('openEditModal', $channel->id)
|
||||||
|
->assertSet('editingChannelId', $channel->id)
|
||||||
|
->call('deleteChannel', $channel->id)
|
||||||
|
->assertSet('editingChannelId', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_the_channel_being_managed_closes_the_account_modal(): void
|
||||||
|
{
|
||||||
|
$channel = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->call('openAccountModal', $channel->id)
|
||||||
|
->assertSet('managingChannelId', $channel->id)
|
||||||
|
->call('deleteChannel', $channel->id)
|
||||||
|
->assertSet('managingChannelId', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_confirmation_states_what_will_be_removed(): void
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
$channel = PlatformChannel::factory()->create(['display_name' => 'Tech Community']);
|
||||||
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
|
|
||||||
|
RouteArticle::factory()->create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
'article_id' => $article->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ArticlePublication::factory()->create([
|
||||||
|
'article_id' => $article->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->assertSee('1 article routed to it')
|
||||||
|
->assertSee('1 publication record');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_each_card_shows_its_own_counts_not_the_totals(): void
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
$busy = PlatformChannel::factory()->create(['name' => 'aaa-busy', 'display_name' => 'Busy Channel']);
|
||||||
|
$quiet = PlatformChannel::factory()->create(['name' => 'zzz-quiet', 'display_name' => 'Quiet Channel']);
|
||||||
|
|
||||||
|
foreach (range(1, 3) as $ignored) {
|
||||||
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
|
RouteArticle::factory()->create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $busy->id,
|
||||||
|
'article_id' => $article->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$quietArticle = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
|
RouteArticle::factory()->create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $quiet->id,
|
||||||
|
'article_id' => $quietArticle->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->assertSee('3 articles routed to it')
|
||||||
|
->assertSee('1 article routed to it');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_confirmation_pluralises_counts(): void
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
$channel = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
foreach (range(1, 2) as $ignored) {
|
||||||
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
|
RouteArticle::factory()->create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
'article_id' => $article->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Livewire::test(Channels::class)
|
||||||
|
->assertSee('2 articles routed to it')
|
||||||
|
->assertSee('0 publication records');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -336,22 +336,33 @@ public function test_it_keys_the_chart_on_its_data_so_a_range_change_replaces_it
|
||||||
Livewire::test(Dashboard::class)->call('applyRange', '2026-08-01', '2026-08-31')
|
Livewire::test(Dashboard::class)->call('applyRange', '2026-08-01', '2026-08-31')
|
||||||
);
|
);
|
||||||
|
|
||||||
preg_match('/wire:key="(chart-[a-f0-9]+)"/', $july, $julyKey);
|
if (preg_match('/wire:key="(chart-[a-f0-9]+)"/', $july, $julyKey) !== 1) {
|
||||||
preg_match('/wire:key="(chart-[a-f0-9]+)"/', $august, $augustKey);
|
$this->fail('July fragments contained no chart key.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/wire:key="(chart-[a-f0-9]+)"/', $august, $augustKey) !== 1) {
|
||||||
|
$this->fail('August fragments contained no chart key.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertNotEmpty($julyKey);
|
|
||||||
$this->assertNotEmpty($augustKey);
|
|
||||||
$this->assertNotSame($julyKey[1], $augustKey[1]);
|
$this->assertNotSame($julyKey[1], $augustKey[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_keys_each_chart_separately_when_their_payloads_match(): void
|
public function test_it_gives_concurrently_rendered_charts_distinct_keys(): void
|
||||||
{
|
{
|
||||||
|
RouteArticle::factory()->create([
|
||||||
|
'approval_status' => ApprovalStatusEnum::APPROVED,
|
||||||
|
'publish_status' => PublishStatusEnum::PUBLISHED,
|
||||||
|
'decided_at' => Carbon::parse('2026-07-10 12:00:00'),
|
||||||
|
'updated_at' => Carbon::parse('2026-07-10 12:00:00'),
|
||||||
|
]);
|
||||||
|
|
||||||
$fragments = $this->islandFragments(
|
$fragments = $this->islandFragments(
|
||||||
Livewire::test(Dashboard::class)->call('applyRange', '2026-07-01', '2026-07-31')
|
Livewire::test(Dashboard::class)->call('applyRange', '2026-07-01', '2026-07-31')
|
||||||
);
|
);
|
||||||
|
|
||||||
preg_match_all('/wire:key="(chart-[a-f0-9]+)"/', $fragments, $keys);
|
preg_match_all('/wire:key="(chart-[a-f0-9]+)"/', $fragments, $keys);
|
||||||
|
|
||||||
|
$this->assertCount(2, $keys[1]);
|
||||||
$this->assertSame($keys[1], array_unique($keys[1]));
|
$this->assertSame($keys[1], array_unique($keys[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
use App\Actions\PublishRouteArticleAction;
|
use App\Actions\PublishRouteArticleAction;
|
||||||
use App\Enums\NotificationTypeEnum;
|
use App\Enums\NotificationTypeEnum;
|
||||||
use App\Enums\PublishStatusEnum;
|
use App\Enums\PublishStatusEnum;
|
||||||
|
|
@ -17,7 +18,6 @@
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Modules\Lemmy\Services\LemmyApiService;
|
use App\Modules\Lemmy\Services\LemmyApiService;
|
||||||
use App\Modules\Lemmy\Services\LemmyPublisher;
|
use App\Modules\Lemmy\Services\LemmyPublisher;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
use App\Services\Log\LogSaver;
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use App\Services\Publishing\ArticlePublishingService;
|
use App\Services\Publishing\ArticlePublishingService;
|
||||||
|
|
@ -124,8 +124,8 @@ public function test_a_skipped_duplicate_is_not_reported_as_a_publish_failure():
|
||||||
|
|
||||||
PlatformChannelPost::storePost($channel, '555', $article->url, 'Already Posted');
|
PlatformChannelPost::storePost($channel, '555', $article->url, 'Already Posted');
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publisher = Mockery::mock(LemmyPublisher::class);
|
$publisher = Mockery::mock(LemmyPublisher::class);
|
||||||
$publisher->shouldNotReceive('publishToChannel');
|
$publisher->shouldNotReceive('publishToChannel');
|
||||||
|
|
@ -141,8 +141,8 @@ public function test_a_genuine_failure_is_still_reported(): void
|
||||||
{
|
{
|
||||||
[$routeArticle] = $this->fixture;
|
[$routeArticle] = $this->fixture;
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publisher = Mockery::mock(LemmyPublisher::class);
|
$publisher = Mockery::mock(LemmyPublisher::class);
|
||||||
$publisher->shouldReceive('publishToChannel')->andThrow(new \RuntimeException('Lemmy rejected the post'));
|
$publisher->shouldReceive('publishToChannel')->andThrow(new \RuntimeException('Lemmy rejected the post'));
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Actions\CreateRouteArticlesAction;
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
|
use App\Actions\ValidateArticleAction;
|
||||||
use App\Enums\ApprovalStatusEnum;
|
use App\Enums\ApprovalStatusEnum;
|
||||||
use App\Livewire\Articles;
|
use App\Livewire\Articles;
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
|
|
@ -11,8 +14,6 @@
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Article\ValidationService;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
|
@ -124,8 +125,8 @@ public function test_pending_articles_are_not_stamped_on_creation(): void
|
||||||
|
|
||||||
private function validate(Article $article): void
|
private function validate(Article $article): void
|
||||||
{
|
{
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')
|
$fetcher->shouldReceive('execute')
|
||||||
->with($article)
|
->with($article)
|
||||||
->once()
|
->once()
|
||||||
->andReturn([
|
->andReturn([
|
||||||
|
|
@ -134,7 +135,7 @@ private function validate(Article $article): void
|
||||||
'full_article' => 'Body text',
|
'full_article' => 'Body text',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
(new ValidationService($fetcher))->validate($article);
|
(new ValidateArticleAction($fetcher, new CreateRouteArticlesAction))->execute($article);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function articleOnRouteWithoutKeywords(bool $autoApprove): Article
|
private function articleOnRouteWithoutKeywords(bool $autoApprove): Article
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Actions\CreateRouteArticlesAction;
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
|
use App\Actions\ValidateArticleAction;
|
||||||
use App\Enums\ApprovalStatusEnum;
|
use App\Enums\ApprovalStatusEnum;
|
||||||
use App\Events\NewArticleFetched;
|
use App\Events\NewArticleFetched;
|
||||||
use App\Listeners\ValidateArticleListener;
|
use App\Listeners\ValidateArticleListener;
|
||||||
|
|
@ -11,8 +14,6 @@
|
||||||
use App\Models\Keyword;
|
use App\Models\Keyword;
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Article\ValidationService;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
@ -23,8 +24,8 @@ class ValidateArticleListenerTest extends TestCase
|
||||||
|
|
||||||
private function createListenerWithMockedFetcher(?string $content = 'Some article content'): ValidateArticleListener
|
private function createListenerWithMockedFetcher(?string $content = 'Some article content'): ValidateArticleListener
|
||||||
{
|
{
|
||||||
$articleFetcher = Mockery::mock(ArticleFetcher::class);
|
$articleFetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcher->shouldReceive('fetchArticleData')->andReturn(
|
$articleFetcher->shouldReceive('execute')->andReturn(
|
||||||
$content ? [
|
$content ? [
|
||||||
'title' => 'Test Title',
|
'title' => 'Test Title',
|
||||||
'description' => 'Test description',
|
'description' => 'Test description',
|
||||||
|
|
@ -33,7 +34,7 @@ private function createListenerWithMockedFetcher(?string $content = 'Some articl
|
||||||
);
|
);
|
||||||
|
|
||||||
return new ValidateArticleListener(
|
return new ValidateArticleListener(
|
||||||
new ValidationService($articleFetcher)
|
new ValidateArticleAction($articleFetcher, new CreateRouteArticlesAction)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,11 +111,11 @@ public function test_listener_skips_articles_with_existing_publication(): void
|
||||||
|
|
||||||
public function test_listener_handles_validation_errors_gracefully(): void
|
public function test_listener_handles_validation_errors_gracefully(): void
|
||||||
{
|
{
|
||||||
$articleFetcher = Mockery::mock(ArticleFetcher::class);
|
$articleFetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcher->shouldReceive('fetchArticleData')->andThrow(new \Exception('Fetch failed'));
|
$articleFetcher->shouldReceive('execute')->andThrow(new \Exception('Fetch failed'));
|
||||||
|
|
||||||
$listener = new ValidateArticleListener(
|
$listener = new ValidateArticleListener(
|
||||||
new ValidationService($articleFetcher)
|
new ValidateArticleAction($articleFetcher, new CreateRouteArticlesAction)
|
||||||
);
|
);
|
||||||
|
|
||||||
$feed = Feed::factory()->create();
|
$feed = Feed::factory()->create();
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Traits;
|
|
||||||
|
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
|
||||||
use Mockery;
|
|
||||||
use Mockery\MockInterface;
|
|
||||||
|
|
||||||
trait CreatesArticleFetcher
|
|
||||||
{
|
|
||||||
protected function createArticleFetcher(?LogSaver $logSaver = null): ArticleFetcher
|
|
||||||
{
|
|
||||||
if (! $logSaver) {
|
|
||||||
$logSaver = Mockery::mock(LogSaver::class);
|
|
||||||
$logSaver->shouldReceive('info')->zeroOrMoreTimes();
|
|
||||||
$logSaver->shouldReceive('warning')->zeroOrMoreTimes();
|
|
||||||
$logSaver->shouldReceive('error')->zeroOrMoreTimes();
|
|
||||||
$logSaver->shouldReceive('debug')->zeroOrMoreTimes();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ArticleFetcher($logSaver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array{ArticleFetcher, MockInterface} */
|
|
||||||
protected function createArticleFetcherWithMockedLogSaver(): array
|
|
||||||
{
|
|
||||||
$logSaver = Mockery::mock(LogSaver::class);
|
|
||||||
$logSaver->shouldReceive('info')->zeroOrMoreTimes();
|
|
||||||
$logSaver->shouldReceive('warning')->zeroOrMoreTimes();
|
|
||||||
$logSaver->shouldReceive('error')->zeroOrMoreTimes();
|
|
||||||
$logSaver->shouldReceive('debug')->zeroOrMoreTimes();
|
|
||||||
|
|
||||||
$articleFetcher = new ArticleFetcher($logSaver);
|
|
||||||
|
|
||||||
return [$articleFetcher, $logSaver];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
52
tests/Traits/CreatesFetchActions.php
Normal file
52
tests/Traits/CreatesFetchActions.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Traits;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
|
use App\Actions\FetchFeedArticlesAction;
|
||||||
|
use App\Actions\FetchRssArticlesAction;
|
||||||
|
use App\Actions\FetchWebsiteArticlesAction;
|
||||||
|
use App\Actions\SaveArticleAction;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Mockery;
|
||||||
|
use Mockery\MockInterface;
|
||||||
|
|
||||||
|
trait CreatesFetchActions
|
||||||
|
{
|
||||||
|
protected function createFeedFetcher(?LogSaver $logSaver = null): FetchFeedArticlesAction
|
||||||
|
{
|
||||||
|
$logSaver ??= $this->mockLogSaver();
|
||||||
|
$saveArticle = new SaveArticleAction($logSaver);
|
||||||
|
|
||||||
|
return new FetchFeedArticlesAction(
|
||||||
|
$logSaver,
|
||||||
|
new FetchRssArticlesAction($logSaver, $saveArticle),
|
||||||
|
new FetchWebsiteArticlesAction($logSaver, $saveArticle),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createArticleDataFetcher(?LogSaver $logSaver = null): FetchArticleDataAction
|
||||||
|
{
|
||||||
|
return new FetchArticleDataAction($logSaver ?? $this->mockLogSaver());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{FetchFeedArticlesAction, MockInterface} */
|
||||||
|
protected function createFeedFetcherWithMockedLogSaver(): array
|
||||||
|
{
|
||||||
|
$logSaver = $this->mockLogSaver();
|
||||||
|
|
||||||
|
return [$this->createFeedFetcher($logSaver), $logSaver];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return LogSaver&MockInterface */
|
||||||
|
private function mockLogSaver(): MockInterface
|
||||||
|
{
|
||||||
|
$logSaver = Mockery::mock(LogSaver::class);
|
||||||
|
$logSaver->shouldReceive('info')->zeroOrMoreTimes();
|
||||||
|
$logSaver->shouldReceive('warning')->zeroOrMoreTimes();
|
||||||
|
$logSaver->shouldReceive('error')->zeroOrMoreTimes();
|
||||||
|
$logSaver->shouldReceive('debug')->zeroOrMoreTimes();
|
||||||
|
|
||||||
|
return $logSaver;
|
||||||
|
}
|
||||||
|
}
|
||||||
215
tests/Unit/Actions/CreateRouteArticlesActionTest.php
Normal file
215
tests/Unit/Actions/CreateRouteArticlesActionTest.php
Normal file
|
|
@ -0,0 +1,215 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
|
use App\Actions\CreateRouteArticlesAction;
|
||||||
|
use App\Enums\ApprovalStatusEnum;
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Models\Keyword;
|
||||||
|
use App\Models\PlatformChannel;
|
||||||
|
use App\Models\Route;
|
||||||
|
use App\Models\RouteArticle;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CreateRouteArticlesActionTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private function action(): CreateRouteArticlesAction
|
||||||
|
{
|
||||||
|
return new CreateRouteArticlesAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function route(bool $isActive = true, ?bool $autoApprove = null): Route
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
$channel = PlatformChannel::factory()->create();
|
||||||
|
|
||||||
|
return Route::create([
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
'platform_channel_id' => $channel->id,
|
||||||
|
'priority' => 50,
|
||||||
|
'is_active' => $isActive,
|
||||||
|
'auto_approve' => $autoApprove,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function articleFor(Route $route): Article
|
||||||
|
{
|
||||||
|
return Article::factory()->create([
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'title' => 'A title',
|
||||||
|
'description' => 'A description',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_creates_a_route_article_per_active_route(): void
|
||||||
|
{
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('route_articles', [
|
||||||
|
'article_id' => $article->id,
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'platform_channel_id' => $route->platform_channel_id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_skips_inactive_routes(): void
|
||||||
|
{
|
||||||
|
$route = $this->route(isActive: false);
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertSame(0, RouteArticle::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_route_without_keywords_is_pending(): void
|
||||||
|
{
|
||||||
|
Setting::setBool('enable_publishing_approvals', true);
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::PENDING, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_matching_keyword_leaves_it_pending(): void
|
||||||
|
{
|
||||||
|
Setting::setBool('enable_publishing_approvals', true);
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
Keyword::create([
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'platform_channel_id' => $route->platform_channel_id,
|
||||||
|
'keyword' => 'brussels',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'news from Brussels today');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::PENDING, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_non_matching_keyword_rejects(): void
|
||||||
|
{
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
Keyword::create([
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'platform_channel_id' => $route->platform_channel_id,
|
||||||
|
'keyword' => 'antwerp',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'news from Brussels today');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::REJECTED, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_keyword_matching_is_case_insensitive(): void
|
||||||
|
{
|
||||||
|
Setting::setBool('enable_publishing_approvals', true);
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
Keyword::create([
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'platform_channel_id' => $route->platform_channel_id,
|
||||||
|
'keyword' => 'BRUSSELS',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'news from brussels today');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::PENDING, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_inactive_keywords_are_ignored(): void
|
||||||
|
{
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
Keyword::create([
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'platform_channel_id' => $route->platform_channel_id,
|
||||||
|
'keyword' => 'antwerp',
|
||||||
|
'is_active' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Setting::setBool('enable_publishing_approvals', true);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'news from Brussels today');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::PENDING, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_route_auto_approve_flag_overrides_the_global_setting(): void
|
||||||
|
{
|
||||||
|
Setting::setBool('enable_publishing_approvals', true);
|
||||||
|
$route = $this->route(autoApprove: true);
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::APPROVED, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_rejected_article_is_never_auto_approved(): void
|
||||||
|
{
|
||||||
|
$route = $this->route(autoApprove: true);
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
Keyword::create([
|
||||||
|
'feed_id' => $route->feed_id,
|
||||||
|
'platform_channel_id' => $route->platform_channel_id,
|
||||||
|
'keyword' => 'antwerp',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'news from Brussels today');
|
||||||
|
|
||||||
|
$this->assertSame(ApprovalStatusEnum::REJECTED, RouteArticle::first()->approval_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_approved_route_article_is_stamped_with_a_decision_time(): void
|
||||||
|
{
|
||||||
|
$route = $this->route(autoApprove: true);
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertNotNull(RouteArticle::first()->decided_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_pending_route_article_has_no_decision_time(): void
|
||||||
|
{
|
||||||
|
Setting::setBool('enable_publishing_approvals', true);
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertNull(RouteArticle::first()->decided_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_running_twice_does_not_duplicate_route_articles(): void
|
||||||
|
{
|
||||||
|
$route = $this->route();
|
||||||
|
$article = $this->articleFor($route);
|
||||||
|
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
$this->action()->execute($article, 'body content');
|
||||||
|
|
||||||
|
$this->assertSame(1, RouteArticle::count());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Unit\Services;
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CreatesArticleFetcher;
|
use Tests\Traits\CreatesFetchActions;
|
||||||
|
|
||||||
class ArticleFetcherTest extends TestCase
|
class FetchFeedArticlesActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use CreatesArticleFetcher, RefreshDatabase;
|
use CreatesFetchActions, RefreshDatabase;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
|
@ -25,19 +24,18 @@ protected function setUp(): void
|
||||||
'*' => Http::response('<html><body>Mock HTML content</body></html>', 200),
|
'*' => Http::response('<html><body>Mock HTML content</body></html>', 200),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Create ArticleFetcher only when needed - tests will create their own
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_articles_from_feed_returns_collection(): void
|
public function test_get_articles_from_feed_returns_collection(): void
|
||||||
{
|
{
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
|
|
||||||
$feed = Feed::factory()->create([
|
$feed = Feed::factory()->create([
|
||||||
'type' => 'rss',
|
'type' => 'rss',
|
||||||
'url' => 'https://example.com/feed.rss',
|
'url' => 'https://example.com/feed.rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
}
|
}
|
||||||
|
|
@ -49,8 +47,8 @@ public function test_get_articles_from_rss_feed_returns_empty_collection(): void
|
||||||
'url' => 'https://example.com/feed.rss',
|
'url' => 'https://example.com/feed.rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
// RSS parsing is not implemented yet, should return empty collection
|
// RSS parsing is not implemented yet, should return empty collection
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
@ -63,8 +61,8 @@ public function test_get_articles_from_website_feed_handles_no_parser(): void
|
||||||
'url' => 'https://unsupported-site.com/',
|
'url' => 'https://unsupported-site.com/',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
// Should return empty collection when no parser is available
|
// Should return empty collection when no parser is available
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
|
|
@ -78,8 +76,8 @@ public function test_get_articles_from_unsupported_feed_type(): void
|
||||||
'url' => 'https://unsupported-feed-type.com/feed',
|
'url' => 'https://unsupported-feed-type.com/feed',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
@ -91,8 +89,8 @@ public function test_fetch_article_data_returns_array(): void
|
||||||
'url' => 'https://example.com/article',
|
'url' => 'https://example.com/article',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createArticleDataFetcher();
|
||||||
$result = $articleFetcher->fetchArticleData($article);
|
$result = $articleFetcher->execute($article);
|
||||||
|
|
||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
// Will be empty array due to unsupported URL in test
|
// Will be empty array due to unsupported URL in test
|
||||||
|
|
@ -105,8 +103,8 @@ public function test_fetch_article_data_handles_invalid_url(): void
|
||||||
'url' => 'invalid-url',
|
'url' => 'invalid-url',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createArticleDataFetcher();
|
||||||
$result = $articleFetcher->fetchArticleData($article);
|
$result = $articleFetcher->execute($article);
|
||||||
|
|
||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
@ -128,8 +126,8 @@ public function test_get_articles_from_feed_with_null_feed_type(): void
|
||||||
$attributes['type'] = 'invalid_type';
|
$attributes['type'] = 'invalid_type';
|
||||||
$property->setValue($feed, $attributes);
|
$property->setValue($feed, $attributes);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
@ -148,8 +146,8 @@ public function test_get_articles_from_website_feed_with_supported_parser(): voi
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Test actual behavior - VRT parser should be available
|
// Test actual behavior - VRT parser should be available
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
// VRT parser will process the mocked HTML response
|
// VRT parser will process the mocked HTML response
|
||||||
|
|
@ -164,8 +162,8 @@ public function test_get_articles_from_website_feed_handles_invalid_url(): void
|
||||||
'url' => 'https://invalid-domain-that-does-not-exist-12345.com/',
|
'url' => 'https://invalid-domain-that-does-not-exist-12345.com/',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createFeedFetcher();
|
||||||
$result = $articleFetcher->getArticlesFromFeed($feed);
|
$result = $articleFetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
@ -183,8 +181,8 @@ public function test_fetch_article_data_with_supported_parser(): void
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Test actual behavior - VRT parser should be available
|
// Test actual behavior - VRT parser should be available
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createArticleDataFetcher();
|
||||||
$result = $articleFetcher->fetchArticleData($article);
|
$result = $articleFetcher->execute($article);
|
||||||
|
|
||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
// VRT parser will process the mocked HTML response
|
// VRT parser will process the mocked HTML response
|
||||||
|
|
@ -196,76 +194,13 @@ public function test_fetch_article_data_handles_unsupported_domain(): void
|
||||||
'url' => 'https://unsupported-domain.com/article',
|
'url' => 'https://unsupported-domain.com/article',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
$articleFetcher = $this->createArticleDataFetcher();
|
||||||
$result = $articleFetcher->fetchArticleData($article);
|
$result = $articleFetcher->execute($article);
|
||||||
|
|
||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_save_article_creates_new_article_when_not_exists(): void
|
|
||||||
{
|
|
||||||
$feed = Feed::factory()->create();
|
|
||||||
$url = 'https://example.com/unique-article';
|
|
||||||
|
|
||||||
// Ensure article doesn't exist
|
|
||||||
$this->assertDatabaseMissing('articles', ['url' => $url]);
|
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
|
||||||
// Use reflection to access private method for testing
|
|
||||||
$reflection = new \ReflectionClass($articleFetcher);
|
|
||||||
$saveArticleMethod = $reflection->getMethod('saveArticle');
|
|
||||||
$saveArticleMethod->setAccessible(true);
|
|
||||||
|
|
||||||
$article = $saveArticleMethod->invoke($articleFetcher, $url, $feed->id);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Article::class, $article);
|
|
||||||
$this->assertEquals($url, $article->url);
|
|
||||||
$this->assertEquals($feed->id, $article->feed_id);
|
|
||||||
$this->assertDatabaseHas('articles', ['url' => $url, 'feed_id' => $feed->id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_save_article_returns_existing_article_when_exists(): void
|
|
||||||
{
|
|
||||||
$feed = Feed::factory()->create();
|
|
||||||
$existingArticle = Article::factory()->create([
|
|
||||||
'url' => 'https://example.com/existing-article',
|
|
||||||
'feed_id' => $feed->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Use reflection to access private method for testing
|
|
||||||
$reflection = new \ReflectionClass(ArticleFetcher::class);
|
|
||||||
$saveArticleMethod = $reflection->getMethod('saveArticle');
|
|
||||||
$saveArticleMethod->setAccessible(true);
|
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
|
||||||
$article = $saveArticleMethod->invoke($articleFetcher, $existingArticle->url, $feed->id);
|
|
||||||
|
|
||||||
$this->assertEquals($existingArticle->id, $article->id);
|
|
||||||
$this->assertEquals($existingArticle->url, $article->url);
|
|
||||||
|
|
||||||
// Ensure no duplicate was created
|
|
||||||
$this->assertEquals(1, Article::where('url', $existingArticle->url)->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_save_article_without_feed_id(): void
|
|
||||||
{
|
|
||||||
$url = 'https://example.com/article-without-feed';
|
|
||||||
|
|
||||||
// Use reflection to access private method for testing
|
|
||||||
$reflection = new \ReflectionClass(ArticleFetcher::class);
|
|
||||||
$saveArticleMethod = $reflection->getMethod('saveArticle');
|
|
||||||
$saveArticleMethod->setAccessible(true);
|
|
||||||
|
|
||||||
$articleFetcher = $this->createArticleFetcher();
|
|
||||||
$article = $saveArticleMethod->invoke($articleFetcher, $url, null);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Article::class, $article);
|
|
||||||
$this->assertEquals($url, $article->url);
|
|
||||||
$this->assertNull($article->feed_id);
|
|
||||||
$this->assertDatabaseHas('articles', ['url' => $url, 'feed_id' => null]);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Mockery::close();
|
Mockery::close();
|
||||||
112
tests/Unit/Actions/FetchRssArticlesActionTest.php
Normal file
112
tests/Unit/Actions/FetchRssArticlesActionTest.php
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
|
use App\Actions\FetchRssArticlesAction;
|
||||||
|
use App\Actions\SaveArticleAction;
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class FetchRssArticlesActionTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private function action(): FetchRssArticlesAction
|
||||||
|
{
|
||||||
|
$logSaver = app(LogSaver::class);
|
||||||
|
|
||||||
|
return new FetchRssArticlesAction($logSaver, new SaveArticleAction($logSaver));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function rss(string ...$links): string
|
||||||
|
{
|
||||||
|
$items = '';
|
||||||
|
|
||||||
|
foreach ($links as $link) {
|
||||||
|
$items .= "<item><link>{$link}</link></item>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<?xml version=\"1.0\"?><rss><channel>{$items}</channel></rss>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function feed(): Feed
|
||||||
|
{
|
||||||
|
return Feed::factory()->create([
|
||||||
|
'type' => 'rss',
|
||||||
|
'url' => 'https://example.com/feed.rss',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_saves_an_article_per_rss_item(): void
|
||||||
|
{
|
||||||
|
$feed = $this->feed();
|
||||||
|
|
||||||
|
Http::fake([$feed->url => Http::response(
|
||||||
|
$this->rss('https://example.com/one', 'https://example.com/two'), 200
|
||||||
|
)]);
|
||||||
|
|
||||||
|
$result = $this->action()->execute($feed);
|
||||||
|
|
||||||
|
$this->assertCount(2, $result);
|
||||||
|
$this->assertDatabaseHas('articles', ['url' => 'https://example.com/one', 'feed_id' => $feed->id]);
|
||||||
|
$this->assertDatabaseHas('articles', ['url' => 'https://example.com/two', 'feed_id' => $feed->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_skips_items_with_an_empty_link(): void
|
||||||
|
{
|
||||||
|
$feed = $this->feed();
|
||||||
|
|
||||||
|
Http::fake([$feed->url => Http::response(
|
||||||
|
$this->rss('https://example.com/one', ''), 200
|
||||||
|
)]);
|
||||||
|
|
||||||
|
$result = $this->action()->execute($feed);
|
||||||
|
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
$this->assertSame(1, Article::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_empty_for_malformed_xml(): void
|
||||||
|
{
|
||||||
|
$feed = $this->feed();
|
||||||
|
|
||||||
|
Http::fake([$feed->url => Http::response('<not-xml', 200)]);
|
||||||
|
|
||||||
|
$this->assertEmpty($this->action()->execute($feed));
|
||||||
|
$this->assertSame(0, Article::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_empty_when_the_feed_has_no_items(): void
|
||||||
|
{
|
||||||
|
$feed = $this->feed();
|
||||||
|
|
||||||
|
Http::fake([$feed->url => Http::response('<?xml version="1.0"?><rss><channel></channel></rss>', 200)]);
|
||||||
|
|
||||||
|
$this->assertEmpty($this->action()->execute($feed));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_empty_when_the_fetch_throws(): void
|
||||||
|
{
|
||||||
|
$feed = $this->feed();
|
||||||
|
|
||||||
|
Http::fake(fn () => throw new \RuntimeException('connection refused'));
|
||||||
|
|
||||||
|
$this->assertEmpty($this->action()->execute($feed));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_does_not_duplicate_articles_across_runs(): void
|
||||||
|
{
|
||||||
|
$feed = $this->feed();
|
||||||
|
|
||||||
|
Http::fake([$feed->url => Http::response($this->rss('https://example.com/one'), 200)]);
|
||||||
|
|
||||||
|
$this->action()->execute($feed);
|
||||||
|
$this->action()->execute($feed);
|
||||||
|
|
||||||
|
$this->assertSame(1, Article::count());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Unit\Services;
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
|
|
@ -9,11 +9,11 @@
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CreatesArticleFetcher;
|
use Tests\Traits\CreatesFetchActions;
|
||||||
|
|
||||||
class ArticleFetcherRssTest extends TestCase
|
class FetchRssArticlesFeedTest extends TestCase
|
||||||
{
|
{
|
||||||
use CreatesArticleFetcher, RefreshDatabase;
|
use CreatesFetchActions, RefreshDatabase;
|
||||||
|
|
||||||
private string $sampleRss;
|
private string $sampleRss;
|
||||||
|
|
||||||
|
|
@ -54,8 +54,8 @@ public function test_get_articles_from_rss_feed_returns_collection(): void
|
||||||
'url' => 'https://www.theguardian.com/international/rss',
|
'url' => 'https://www.theguardian.com/international/rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
}
|
}
|
||||||
|
|
@ -70,8 +70,8 @@ public function test_get_articles_from_rss_feed_creates_articles(): void
|
||||||
'url' => 'https://www.theguardian.com/international/rss',
|
'url' => 'https://www.theguardian.com/international/rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertCount(2, $result);
|
$this->assertCount(2, $result);
|
||||||
$this->assertDatabaseHas('articles', [
|
$this->assertDatabaseHas('articles', [
|
||||||
|
|
@ -99,8 +99,8 @@ public function test_get_articles_from_rss_feed_does_not_duplicate_existing(): v
|
||||||
'feed_id' => $feed->id,
|
'feed_id' => $feed->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertCount(2, $result);
|
$this->assertCount(2, $result);
|
||||||
$this->assertEquals(1, Article::where('url', 'https://www.theguardian.com/world/2026/mar/08/first-article')->count());
|
$this->assertEquals(1, Article::where('url', 'https://www.theguardian.com/world/2026/mar/08/first-article')->count());
|
||||||
|
|
@ -127,8 +127,8 @@ public function test_get_articles_from_rss_feed_returns_known_articles_when_none
|
||||||
|
|
||||||
$countBeforeFetch = Article::count();
|
$countBeforeFetch = Article::count();
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertCount(2, $result);
|
$this->assertCount(2, $result);
|
||||||
$this->assertSame($countBeforeFetch, Article::count());
|
$this->assertSame($countBeforeFetch, Article::count());
|
||||||
|
|
@ -144,8 +144,8 @@ public function test_get_articles_from_rss_feed_handles_invalid_xml(): void
|
||||||
'url' => 'https://www.theguardian.com/international/rss',
|
'url' => 'https://www.theguardian.com/international/rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertInstanceOf(Collection::class, $result);
|
$this->assertInstanceOf(Collection::class, $result);
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
|
|
@ -163,8 +163,8 @@ public function test_get_articles_from_rss_feed_handles_empty_channel(): void
|
||||||
'url' => 'https://www.theguardian.com/international/rss',
|
'url' => 'https://www.theguardian.com/international/rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
}
|
}
|
||||||
|
|
@ -179,8 +179,8 @@ public function test_get_articles_from_rss_feed_handles_http_failure(): void
|
||||||
'url' => 'https://www.theguardian.com/international/rss',
|
'url' => 'https://www.theguardian.com/international/rss',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
}
|
}
|
||||||
|
|
@ -217,8 +217,8 @@ public function test_get_articles_from_belga_rss_feed_creates_articles(): void
|
||||||
'url' => 'https://www.belganewsagency.eu/feed',
|
'url' => 'https://www.belganewsagency.eu/feed',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = $this->createArticleFetcher();
|
$fetcher = $this->createFeedFetcher();
|
||||||
$result = $fetcher->getArticlesFromFeed($feed);
|
$result = $fetcher->execute($feed);
|
||||||
|
|
||||||
$this->assertCount(2, $result);
|
$this->assertCount(2, $result);
|
||||||
$this->assertDatabaseHas('articles', [
|
$this->assertDatabaseHas('articles', [
|
||||||
64
tests/Unit/Actions/FetchWebsiteArticlesActionTest.php
Normal file
64
tests/Unit/Actions/FetchWebsiteArticlesActionTest.php
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
|
use App\Actions\FetchWebsiteArticlesAction;
|
||||||
|
use App\Actions\SaveArticleAction;
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use App\Services\Log\LogSaver;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class FetchWebsiteArticlesActionTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private function action(): FetchWebsiteArticlesAction
|
||||||
|
{
|
||||||
|
$logSaver = app(LogSaver::class);
|
||||||
|
|
||||||
|
return new FetchWebsiteArticlesAction($logSaver, new SaveArticleAction($logSaver));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_empty_when_no_parser_matches_the_feed(): void
|
||||||
|
{
|
||||||
|
Http::fake(['*' => Http::response('<html></html>', 200)]);
|
||||||
|
|
||||||
|
$feed = Feed::factory()->create([
|
||||||
|
'type' => 'website',
|
||||||
|
'url' => 'https://no-parser-for-this-domain.example/',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEmpty($this->action()->execute($feed));
|
||||||
|
$this->assertSame(0, Article::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_empty_when_the_fetch_throws(): void
|
||||||
|
{
|
||||||
|
Http::fake(fn () => throw new \RuntimeException('connection refused'));
|
||||||
|
|
||||||
|
$feed = Feed::factory()->create([
|
||||||
|
'type' => 'website',
|
||||||
|
'url' => 'https://www.vrt.be/vrtnws/nl/',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEmpty($this->action()->execute($feed));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_a_collection_for_a_feed_with_a_parser(): void
|
||||||
|
{
|
||||||
|
Http::fake([
|
||||||
|
'https://www.vrt.be/vrtnws/nl/' => Http::response('<html><body>Sample VRT content</body></html>', 200),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$feed = Feed::factory()->create([
|
||||||
|
'type' => 'website',
|
||||||
|
'url' => 'https://www.vrt.be/vrtnws/nl/',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Collection::class, $this->action()->execute($feed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Unit\Services;
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Models\Language;
|
use App\Models\Language;
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Tests\Traits\CreatesArticleFetcher;
|
use Tests\Traits\CreatesFetchActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Belga discovery runs through the website path against a JSON API rather than
|
* Belga discovery runs through the website path against a JSON API rather than
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
* registers a catch-all Http::fake in setUp() that a per-test fake cannot
|
* registers a catch-all Http::fake in setUp() that a per-test fake cannot
|
||||||
* override.
|
* override.
|
||||||
*/
|
*/
|
||||||
class ArticleFetcherBelgaTest extends TestCase
|
class FetchWebsiteArticlesBelgaTest extends TestCase
|
||||||
{
|
{
|
||||||
use CreatesArticleFetcher, RefreshDatabase;
|
use CreatesFetchActions, RefreshDatabase;
|
||||||
|
|
||||||
private function apiResponse(): string
|
private function apiResponse(): string
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +45,7 @@ public function test_creates_articles_from_belga_api_response(): void
|
||||||
{
|
{
|
||||||
Http::fake(['*' => Http::response($this->apiResponse(), 200)]);
|
Http::fake(['*' => Http::response($this->apiResponse(), 200)]);
|
||||||
|
|
||||||
$result = $this->createArticleFetcher()->getArticlesFromFeed($this->belgaFeed());
|
$result = $this->createFeedFetcher()->execute($this->belgaFeed());
|
||||||
|
|
||||||
$this->assertCount(6, $result);
|
$this->assertCount(6, $result);
|
||||||
$this->assertDatabaseHas('articles', [
|
$this->assertDatabaseHas('articles', [
|
||||||
|
|
@ -62,7 +62,7 @@ public function test_associates_created_articles_with_the_feed(): void
|
||||||
|
|
||||||
$feed = $this->belgaFeed();
|
$feed = $this->belgaFeed();
|
||||||
|
|
||||||
$this->createArticleFetcher()->getArticlesFromFeed($feed);
|
$this->createFeedFetcher()->execute($feed);
|
||||||
|
|
||||||
$this->assertDatabaseHas('articles', [
|
$this->assertDatabaseHas('articles', [
|
||||||
'url' => 'https://www.belganewsagency.eu/press-releases/35285/',
|
'url' => 'https://www.belganewsagency.eu/press-releases/35285/',
|
||||||
|
|
@ -76,7 +76,7 @@ public function test_returns_empty_collection_when_api_returns_no_articles(): vo
|
||||||
// and must be a no-op rather than an error.
|
// and must be a no-op rather than an error.
|
||||||
Http::fake(['*' => Http::response('{"data":[],"_meta":{"total":0}}', 200)]);
|
Http::fake(['*' => Http::response('{"data":[],"_meta":{"total":0}}', 200)]);
|
||||||
|
|
||||||
$result = $this->createArticleFetcher()->getArticlesFromFeed($this->belgaFeed());
|
$result = $this->createFeedFetcher()->execute($this->belgaFeed());
|
||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
$this->assertDatabaseCount('articles', 0);
|
$this->assertDatabaseCount('articles', 0);
|
||||||
|
|
@ -87,7 +87,7 @@ public function test_returns_empty_collection_when_api_returns_an_error_page():
|
||||||
// The failure mode that caused #115: a 404 HTML body reaching the parser.
|
// The failure mode that caused #115: a 404 HTML body reaching the parser.
|
||||||
Http::fake(['*' => Http::response('<html><body>404 Not Found</body></html>', 200)]);
|
Http::fake(['*' => Http::response('<html><body>404 Not Found</body></html>', 200)]);
|
||||||
|
|
||||||
$result = $this->createArticleFetcher()->getArticlesFromFeed($this->belgaFeed());
|
$result = $this->createFeedFetcher()->execute($this->belgaFeed());
|
||||||
|
|
||||||
$this->assertEmpty($result);
|
$this->assertEmpty($result);
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Unit\Actions;
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
use App\Actions\PublishRouteArticleAction;
|
use App\Actions\PublishRouteArticleAction;
|
||||||
use App\Enums\NotificationTypeEnum;
|
use App\Enums\NotificationTypeEnum;
|
||||||
use App\Enums\PublishStatusEnum;
|
use App\Enums\PublishStatusEnum;
|
||||||
|
|
@ -10,7 +11,6 @@
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use App\Services\Publishing\ArticlePublishingService;
|
use App\Services\Publishing\ArticlePublishingService;
|
||||||
use App\Services\Publishing\PublishOutcome;
|
use App\Services\Publishing\PublishOutcome;
|
||||||
|
|
@ -61,8 +61,8 @@ public function test_publish_uses_stored_article_data_without_fetching(): void
|
||||||
'image_url' => 'https://cdn.test/stored.jpg',
|
'image_url' => 'https://cdn.test/stored.jpg',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldReceive('publishRouteArticle')
|
$publishingService->shouldReceive('publishRouteArticle')
|
||||||
|
|
@ -87,8 +87,8 @@ public function test_publish_body_comes_from_description_not_content(): void
|
||||||
'content' => 'The very much longer full article body text',
|
'content' => 'The very much longer full article body text',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$captured = null;
|
$captured = null;
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
@ -116,8 +116,8 @@ public function test_publish_falls_back_to_fetching_when_description_is_blank():
|
||||||
|
|
||||||
$fetched = ['title' => 'Fetched Title', 'description' => 'Fetched description'];
|
$fetched = ['title' => 'Fetched Title', 'description' => 'Fetched description'];
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')->once()->andReturn($fetched);
|
$fetcher->shouldReceive('execute')->once()->andReturn($fetched);
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldReceive('publishRouteArticle')
|
$publishingService->shouldReceive('publishRouteArticle')
|
||||||
|
|
@ -141,8 +141,8 @@ public function test_publish_falls_back_to_fetching_when_article_has_no_stored_d
|
||||||
'thumbnail' => 'https://cdn.test/fetched.jpg',
|
'thumbnail' => 'https://cdn.test/fetched.jpg',
|
||||||
];
|
];
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')->once()->andReturn($fetched);
|
$fetcher->shouldReceive('execute')->once()->andReturn($fetched);
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldReceive('publishRouteArticle')
|
$publishingService->shouldReceive('publishRouteArticle')
|
||||||
|
|
@ -160,8 +160,8 @@ public function test_publish_fails_when_fallback_fetch_returns_nothing(): void
|
||||||
{
|
{
|
||||||
$routeArticle = $this->createRouteArticle(['title' => 'Unreachable Article'], unvalidated: true);
|
$routeArticle = $this->createRouteArticle(['title' => 'Unreachable Article'], unvalidated: true);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')->once()->andReturn([]);
|
$fetcher->shouldReceive('execute')->once()->andReturn([]);
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldNotReceive('publishRouteArticle');
|
$publishingService->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
@ -181,8 +181,8 @@ public function test_a_failure_stores_the_reason_and_stops_further_attempts(): v
|
||||||
{
|
{
|
||||||
$routeArticle = $this->createRouteArticle([], unvalidated: true);
|
$routeArticle = $this->createRouteArticle([], unvalidated: true);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')->andReturn([]);
|
$fetcher->shouldReceive('execute')->andReturn([]);
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
|
|
@ -205,8 +205,8 @@ public function test_a_successful_publish_clears_an_earlier_failure(): void
|
||||||
]);
|
]);
|
||||||
$routeArticle->recordPublishFailed('an earlier failure');
|
$routeArticle->recordPublishFailed('an earlier failure');
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldReceive('publishRouteArticle')
|
$publishingService->shouldReceive('publishRouteArticle')
|
||||||
|
|
@ -226,8 +226,8 @@ public function test_publish_fails_when_fallback_recovers_only_a_title(): void
|
||||||
{
|
{
|
||||||
$routeArticle = $this->createRouteArticle([], unvalidated: true);
|
$routeArticle = $this->createRouteArticle([], unvalidated: true);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')->once()->andReturn(['title' => 'Recovered Title']);
|
$fetcher->shouldReceive('execute')->once()->andReturn(['title' => 'Recovered Title']);
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldNotReceive('publishRouteArticle');
|
$publishingService->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
@ -245,8 +245,8 @@ public function test_publish_succeeds_when_fallback_returns_a_description_withou
|
||||||
|
|
||||||
$fetched = ['title' => 'Recovered Title', 'description' => 'Recovered description'];
|
$fetched = ['title' => 'Recovered Title', 'description' => 'Recovered description'];
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldReceive('fetchArticleData')->once()->andReturn($fetched);
|
$fetcher->shouldReceive('execute')->once()->andReturn($fetched);
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldReceive('publishRouteArticle')
|
$publishingService->shouldReceive('publishRouteArticle')
|
||||||
|
|
@ -268,8 +268,8 @@ public function test_publish_does_not_refetch_for_articles_stored_before_image_u
|
||||||
'image_url' => null,
|
'image_url' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fetcher = Mockery::mock(ArticleFetcher::class);
|
$fetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$fetcher->shouldNotReceive('fetchArticleData');
|
$fetcher->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
$publishingService = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingService->shouldReceive('publishRouteArticle')
|
$publishingService->shouldReceive('publishRouteArticle')
|
||||||
|
|
|
||||||
73
tests/Unit/Actions/SaveArticleActionTest.php
Normal file
73
tests/Unit/Actions/SaveArticleActionTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
|
use App\Actions\SaveArticleAction;
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Models\Feed;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SaveArticleActionTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private function action(): SaveArticleAction
|
||||||
|
{
|
||||||
|
return app(SaveArticleAction::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_creates_an_article_that_does_not_exist(): void
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
$url = 'https://example.com/unique-article';
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('articles', ['url' => $url]);
|
||||||
|
|
||||||
|
$article = $this->action()->execute($url, $feed->id);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Article::class, $article);
|
||||||
|
$this->assertSame($url, $article->url);
|
||||||
|
$this->assertSame($feed->id, $article->feed_id);
|
||||||
|
$this->assertDatabaseHas('articles', ['url' => $url, 'feed_id' => $feed->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_the_existing_article_instead_of_duplicating(): void
|
||||||
|
{
|
||||||
|
$feed = Feed::factory()->create();
|
||||||
|
$existing = Article::factory()->create([
|
||||||
|
'url' => 'https://example.com/existing-article',
|
||||||
|
'feed_id' => $feed->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$article = $this->action()->execute($existing->url, $feed->id);
|
||||||
|
|
||||||
|
$this->assertSame($existing->id, $article->id);
|
||||||
|
$this->assertSame(1, Article::where('url', $existing->url)->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_creates_an_article_without_a_feed(): void
|
||||||
|
{
|
||||||
|
$url = 'https://example.com/article-without-feed';
|
||||||
|
|
||||||
|
$article = $this->action()->execute($url, null);
|
||||||
|
|
||||||
|
$this->assertSame($url, $article->url);
|
||||||
|
$this->assertNull($article->feed_id);
|
||||||
|
$this->assertDatabaseHas('articles', ['url' => $url, 'feed_id' => null]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_derives_a_readable_fallback_title_from_the_url(): void
|
||||||
|
{
|
||||||
|
$article = $this->action()->execute('https://example.com/some-great_story.html');
|
||||||
|
|
||||||
|
$this->assertSame('Some Great Story', $article->title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_falls_back_to_untitled_when_the_url_has_no_usable_path(): void
|
||||||
|
{
|
||||||
|
$article = $this->action()->execute('https://example.com/');
|
||||||
|
|
||||||
|
$this->assertSame('Untitled Article', $article->title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Unit\Services;
|
namespace Tests\Unit\Actions;
|
||||||
|
|
||||||
|
use App\Actions\CreateRouteArticlesAction;
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
|
use App\Actions\ValidateArticleAction;
|
||||||
use App\Enums\ApprovalStatusEnum;
|
use App\Enums\ApprovalStatusEnum;
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
|
|
@ -10,26 +13,24 @@
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Article\ValidationService;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ValidationServiceTest extends TestCase
|
class ValidateArticleActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
private ValidationService $validationService;
|
private ValidateArticleAction $validateArticle;
|
||||||
|
|
||||||
private MockInterface $articleFetcher;
|
private MockInterface $articleFetcher;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->articleFetcher = Mockery::mock(ArticleFetcher::class);
|
$this->articleFetcher = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$this->validationService = new ValidationService($this->articleFetcher);
|
$this->validateArticle = new ValidateArticleAction($this->articleFetcher, new CreateRouteArticlesAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
|
|
@ -55,7 +56,7 @@ private function mockFetchReturning(Article $article, ?string $content, ?string
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->articleFetcher
|
$this->articleFetcher
|
||||||
->shouldReceive('fetchArticleData')
|
->shouldReceive('execute')
|
||||||
->with($article)
|
->with($article)
|
||||||
->once()
|
->once()
|
||||||
->andReturn($data);
|
->andReturn($data);
|
||||||
|
|
@ -75,7 +76,7 @@ public function test_validate_sets_validated_at_on_article(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium');
|
$this->mockFetchReturning($article, 'Article about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertNotNull($article->fresh()->validated_at);
|
$this->assertNotNull($article->fresh()->validated_at);
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +90,7 @@ public function test_validate_creates_route_articles_for_active_routes(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Some article content');
|
$this->mockFetchReturning($article, 'Some article content');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertCount(2, RouteArticle::where('article_id', $article->id)->get());
|
$this->assertCount(2, RouteArticle::where('article_id', $article->id)->get());
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +104,7 @@ public function test_validate_skips_inactive_routes(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Some article content');
|
$this->mockFetchReturning($article, 'Some article content');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertCount(1, RouteArticle::where('article_id', $article->id)->get());
|
$this->assertCount(1, RouteArticle::where('article_id', $article->id)->get());
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +123,7 @@ public function test_validate_sets_pending_when_keywords_match(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium politics');
|
$this->mockFetchReturning($article, 'Article about Belgium politics');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
||||||
|
|
@ -142,7 +143,7 @@ public function test_validate_sets_rejected_when_no_keywords_match(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about random topics and weather');
|
$this->mockFetchReturning($article, 'Article about random topics and weather');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::REJECTED, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::REJECTED, $routeArticle->approval_status);
|
||||||
|
|
@ -156,7 +157,7 @@ public function test_validate_sets_pending_when_route_has_no_keywords(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about random topics');
|
$this->mockFetchReturning($article, 'Article about random topics');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
||||||
|
|
@ -191,7 +192,7 @@ public function test_validate_different_routes_get_different_statuses(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium');
|
$this->mockFetchReturning($article, 'Article about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$ra1 = RouteArticle::where('article_id', $article->id)
|
$ra1 = RouteArticle::where('article_id', $article->id)
|
||||||
->where('platform_channel_id', $channel1->id)->first();
|
->where('platform_channel_id', $channel1->id)->first();
|
||||||
|
|
@ -218,7 +219,7 @@ public function test_validate_auto_approves_when_global_setting_off_and_keywords
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium');
|
$this->mockFetchReturning($article, 'Article about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::APPROVED, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::APPROVED, $routeArticle->approval_status);
|
||||||
|
|
@ -243,7 +244,7 @@ public function test_validate_route_auto_approve_overrides_global_setting(): voi
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium');
|
$this->mockFetchReturning($article, 'Article about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::APPROVED, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::APPROVED, $routeArticle->approval_status);
|
||||||
|
|
@ -268,7 +269,7 @@ public function test_validate_route_auto_approve_false_overrides_global_off(): v
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium');
|
$this->mockFetchReturning($article, 'Article about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
||||||
|
|
@ -290,7 +291,7 @@ public function test_validate_does_not_auto_approve_rejected_articles(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Random content no match');
|
$this->mockFetchReturning($article, 'Random content no match');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::REJECTED, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::REJECTED, $routeArticle->approval_status);
|
||||||
|
|
@ -304,7 +305,7 @@ public function test_validate_creates_no_route_articles_when_content_fetch_fails
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, null);
|
$this->mockFetchReturning($article, null);
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertCount(0, RouteArticle::where('article_id', $article->id)->get());
|
$this->assertCount(0, RouteArticle::where('article_id', $article->id)->get());
|
||||||
$this->assertNotNull($article->fresh()->validated_at);
|
$this->assertNotNull($article->fresh()->validated_at);
|
||||||
|
|
@ -321,7 +322,7 @@ public function test_validate_updates_article_metadata(): void
|
||||||
]);
|
]);
|
||||||
$this->mockFetchReturning($article, 'Content about Belgium', 'New Title', 'New description');
|
$this->mockFetchReturning($article, 'Content about Belgium', 'New Title', 'New description');
|
||||||
|
|
||||||
$result = $this->validationService->validate($article);
|
$result = $this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertEquals('New Title', $result->title);
|
$this->assertEquals('New Title', $result->title);
|
||||||
$this->assertEquals('New description', $result->description);
|
$this->assertEquals('New description', $result->description);
|
||||||
|
|
@ -336,7 +337,7 @@ public function test_validate_sets_validated_at_on_route_articles(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Content about something');
|
$this->mockFetchReturning($article, 'Content about something');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertNotNull($routeArticle->validated_at);
|
$this->assertNotNull($routeArticle->validated_at);
|
||||||
|
|
@ -356,7 +357,7 @@ public function test_validate_keyword_matching_is_case_insensitive(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about BELGIUM politics');
|
$this->mockFetchReturning($article, 'Article about BELGIUM politics');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
$this->assertEquals(ApprovalStatusEnum::PENDING, $routeArticle->approval_status);
|
||||||
|
|
@ -376,7 +377,7 @@ public function test_validate_only_uses_active_keywords(): void
|
||||||
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
$article = Article::factory()->create(['feed_id' => $feed->id]);
|
||||||
$this->mockFetchReturning($article, 'Article about Belgium');
|
$this->mockFetchReturning($article, 'Article about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
// No active keywords = matches everything = pending
|
// No active keywords = matches everything = pending
|
||||||
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
$routeArticle = RouteArticle::where('article_id', $article->id)->first();
|
||||||
|
|
@ -394,7 +395,7 @@ public function test_validate_stores_thumbnail_in_image_url(): void
|
||||||
]);
|
]);
|
||||||
$this->mockFetchReturning($article, 'Content about Belgium', thumbnail: 'https://example.com/thumb.jpg');
|
$this->mockFetchReturning($article, 'Content about Belgium', thumbnail: 'https://example.com/thumb.jpg');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertEquals('https://example.com/thumb.jpg', $article->fresh()->image_url);
|
$this->assertEquals('https://example.com/thumb.jpg', $article->fresh()->image_url);
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +411,7 @@ public function test_validate_stores_thumbnail_when_full_article_is_missing(): v
|
||||||
]);
|
]);
|
||||||
$this->mockFetchReturning($article, null, thumbnail: 'https://example.com/thumb.jpg');
|
$this->mockFetchReturning($article, null, thumbnail: 'https://example.com/thumb.jpg');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertEquals('https://example.com/thumb.jpg', $article->fresh()->image_url);
|
$this->assertEquals('https://example.com/thumb.jpg', $article->fresh()->image_url);
|
||||||
}
|
}
|
||||||
|
|
@ -426,7 +427,7 @@ public function test_validate_leaves_image_url_null_when_parser_returns_no_thumb
|
||||||
]);
|
]);
|
||||||
$this->mockFetchReturning($article, 'Content about Belgium');
|
$this->mockFetchReturning($article, 'Content about Belgium');
|
||||||
|
|
||||||
$this->validationService->validate($article);
|
$this->validateArticle->execute($article);
|
||||||
|
|
||||||
$this->assertNull($article->fresh()->image_url);
|
$this->assertNull($article->fresh()->image_url);
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace Tests\Unit\Jobs;
|
namespace Tests\Unit\Jobs;
|
||||||
|
|
||||||
|
use App\Actions\FetchFeedArticlesAction;
|
||||||
use App\Jobs\ArticleDiscoveryForFeedJob;
|
use App\Jobs\ArticleDiscoveryForFeedJob;
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
use App\Models\Feed;
|
use App\Models\Feed;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Log\LogSaver;
|
use App\Services\Log\LogSaver;
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
@ -63,9 +63,9 @@ public function test_handle_fetches_articles_and_updates_feed(): void
|
||||||
|
|
||||||
$mockArticles = collect(['article1', 'article2']);
|
$mockArticles = collect(['article1', 'article2']);
|
||||||
|
|
||||||
// Mock ArticleFetcher
|
// Mock the feed fetch
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchFeedArticlesAction::class);
|
||||||
$articleFetcherMock->shouldReceive('getArticlesFromFeed')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->with($feed)
|
->with($feed)
|
||||||
->andReturn($mockArticles);
|
->andReturn($mockArticles);
|
||||||
|
|
@ -189,9 +189,9 @@ public function test_handle_logs_start_message_with_correct_context(): void
|
||||||
|
|
||||||
$mockArticles = collect([new Article]);
|
$mockArticles = collect([new Article]);
|
||||||
|
|
||||||
// Mock ArticleFetcher
|
// Mock the feed fetch
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchFeedArticlesAction::class);
|
||||||
$articleFetcherMock->shouldReceive('getArticlesFromFeed')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($mockArticles);
|
->andReturn($mockArticles);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Unit\Jobs;
|
namespace Tests\Unit\Jobs;
|
||||||
|
|
||||||
|
use App\Actions\FetchArticleDataAction;
|
||||||
use App\Actions\PublishRouteArticleAction;
|
use App\Actions\PublishRouteArticleAction;
|
||||||
use App\Enums\NotificationSeverityEnum;
|
use App\Enums\NotificationSeverityEnum;
|
||||||
use App\Enums\NotificationTypeEnum;
|
use App\Enums\NotificationTypeEnum;
|
||||||
|
|
@ -15,7 +16,6 @@
|
||||||
use App\Models\Route;
|
use App\Models\Route;
|
||||||
use App\Models\RouteArticle;
|
use App\Models\RouteArticle;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Services\Article\ArticleFetcher;
|
|
||||||
use App\Services\Notification\NotificationService;
|
use App\Services\Notification\NotificationService;
|
||||||
use App\Services\Publishing\ArticlePublishingService;
|
use App\Services\Publishing\ArticlePublishingService;
|
||||||
use App\Services\Publishing\PublishOutcome;
|
use App\Services\Publishing\PublishOutcome;
|
||||||
|
|
@ -94,7 +94,7 @@ public function test_job_uses_queueable_trait(): void
|
||||||
|
|
||||||
public function test_handle_returns_early_when_no_approved_route_articles(): void
|
public function test_handle_returns_early_when_no_approved_route_articles(): void
|
||||||
{
|
{
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
$job = new PublishNextArticleJob;
|
$job = new PublishNextArticleJob;
|
||||||
|
|
@ -113,7 +113,7 @@ public function test_handle_returns_early_when_no_unpublished_approved_route_art
|
||||||
'platform_channel_id' => $routeArticle->platform_channel_id,
|
'platform_channel_id' => $routeArticle->platform_channel_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
$job = new PublishNextArticleJob;
|
$job = new PublishNextArticleJob;
|
||||||
|
|
@ -131,7 +131,7 @@ public function test_handle_skips_non_approved_route_articles(): void
|
||||||
|
|
||||||
RouteArticle::factory()->forRoute($route)->pending()->create(['article_id' => $article->id]);
|
RouteArticle::factory()->forRoute($route)->pending()->create(['article_id' => $article->id]);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
$job = new PublishNextArticleJob;
|
$job = new PublishNextArticleJob;
|
||||||
|
|
@ -160,8 +160,8 @@ public function test_handle_publishes_oldest_approved_route_article(): void
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->with(Mockery::on(fn ($article) => $article->id === $olderArticle->id))
|
->with(Mockery::on(fn ($article) => $article->id === $olderArticle->id))
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
@ -189,8 +189,8 @@ public function test_handle_throws_exception_on_publishing_failure(): void
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
$publishException = new PublishException($article, null);
|
$publishException = new PublishException($article, null);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -215,10 +215,10 @@ public function test_handle_skips_publishing_when_last_publication_within_interv
|
||||||
]);
|
]);
|
||||||
Setting::setArticlePublishingInterval(10);
|
Setting::setArticlePublishingInterval(10);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
$articleFetcherMock->shouldNotReceive('fetchArticleData');
|
$articleFetcherMock->shouldNotReceive('execute');
|
||||||
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
||||||
$job = new PublishNextArticleJob;
|
$job = new PublishNextArticleJob;
|
||||||
|
|
@ -235,10 +235,10 @@ public function test_handle_skips_publishing_when_daily_cap_reached(): void
|
||||||
Setting::setArticlePublishingInterval(0);
|
Setting::setArticlePublishingInterval(0);
|
||||||
Setting::setDailyPublishCap(3);
|
Setting::setDailyPublishCap(3);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
$articleFetcherMock->shouldNotReceive('fetchArticleData');
|
$articleFetcherMock->shouldNotReceive('execute');
|
||||||
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
||||||
$job = new PublishNextArticleJob;
|
$job = new PublishNextArticleJob;
|
||||||
|
|
@ -255,8 +255,8 @@ public function test_handle_publishes_when_below_daily_cap(): void
|
||||||
Setting::setArticlePublishingInterval(0);
|
Setting::setArticlePublishingInterval(0);
|
||||||
Setting::setDailyPublishCap(3);
|
Setting::setDailyPublishCap(3);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
||||||
|
|
||||||
|
|
@ -279,8 +279,8 @@ public function test_handle_publishes_when_daily_cap_is_zero(): void
|
||||||
Setting::setArticlePublishingInterval(0);
|
Setting::setArticlePublishingInterval(0);
|
||||||
Setting::setDailyPublishCap(0);
|
Setting::setDailyPublishCap(0);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
||||||
|
|
||||||
|
|
@ -307,10 +307,10 @@ public function test_daily_cap_counts_each_channel_publication_separately(): voi
|
||||||
Setting::setArticlePublishingInterval(0);
|
Setting::setArticlePublishingInterval(0);
|
||||||
Setting::setDailyPublishCap(3);
|
Setting::setDailyPublishCap(3);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
|
|
||||||
$articleFetcherMock->shouldNotReceive('fetchArticleData');
|
$articleFetcherMock->shouldNotReceive('execute');
|
||||||
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
||||||
$job = new PublishNextArticleJob;
|
$job = new PublishNextArticleJob;
|
||||||
|
|
@ -327,8 +327,8 @@ public function test_handle_ignores_publications_from_previous_days(): void
|
||||||
Setting::setArticlePublishingInterval(0);
|
Setting::setArticlePublishingInterval(0);
|
||||||
Setting::setDailyPublishCap(3);
|
Setting::setDailyPublishCap(3);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
||||||
|
|
||||||
|
|
@ -354,8 +354,8 @@ public function test_handle_publishes_when_last_publication_beyond_interval(): v
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -381,8 +381,8 @@ public function test_handle_publishes_when_interval_is_zero(): void
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -408,8 +408,8 @@ public function test_handle_publishes_when_last_publication_exactly_at_interval(
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -432,8 +432,8 @@ public function test_handle_publishes_when_no_previous_publications_exist(): voi
|
||||||
|
|
||||||
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Test Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -454,8 +454,8 @@ public function test_handle_creates_warning_notification_when_no_publication_cre
|
||||||
|
|
||||||
$extractedData = ['title' => 'No Route Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'No Route Article', 'description' => 'Test description'];
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -486,8 +486,8 @@ public function test_handle_creates_notification_on_publish_exception(): void
|
||||||
$extractedData = ['title' => 'Failing Article', 'description' => 'Test description'];
|
$extractedData = ['title' => 'Failing Article', 'description' => 'Test description'];
|
||||||
$publishException = new PublishException($article, null);
|
$publishException = new PublishException($article, null);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn($extractedData);
|
->andReturn($extractedData);
|
||||||
|
|
||||||
|
|
@ -520,8 +520,8 @@ public function test_handle_skips_route_articles_that_previously_failed(): void
|
||||||
$routeArticle = $this->createApprovedRouteArticle();
|
$routeArticle = $this->createApprovedRouteArticle();
|
||||||
$routeArticle->recordPublishFailed('couldnt_find_community');
|
$routeArticle->recordPublishFailed('couldnt_find_community');
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldNotReceive('fetchArticleData');
|
$articleFetcherMock->shouldNotReceive('execute');
|
||||||
|
|
||||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||||
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
||||||
|
|
@ -541,8 +541,8 @@ public function test_handle_publishes_a_later_article_when_the_oldest_has_failed
|
||||||
$next = $this->createApprovedRouteArticle(['title' => 'Next Article']);
|
$next = $this->createApprovedRouteArticle(['title' => 'Next Article']);
|
||||||
$next->update(['created_at' => now()->subDay()]);
|
$next->update(['created_at' => now()->subDay()]);
|
||||||
|
|
||||||
$articleFetcherMock = Mockery::mock(ArticleFetcher::class);
|
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||||
$articleFetcherMock->shouldReceive('fetchArticleData')
|
$articleFetcherMock->shouldReceive('execute')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['title' => 'Next Article', 'description' => 'Test description']);
|
->andReturn(['title' => 'Next Article', 'description' => 'Test description']);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue