# @socialweb.coop/activitypub-testing

tools for testing implementations of [ActivityPub][ActivityPub], a decentralized social networking protocol.

## How to use the `activitypub-testing` CLI

If you have [`npm`](https://en.wikipedia.org/wiki/Npm) installed, You may be able to use the activitypub-testing cli without downloading this source code.

### ad-hoc usage using `npx`

For ad-hoc usage, try:

```shell
⚡  npx @socialweb.coop/activitypub-testing help

activitypub-testing

What?
  activitypub-testing is a cli for testing implementations of ActivityPub[0]

Usage:
  # browse all the tests
  activitypub-testing get tests [--output=<mediaType>]
  # inspect a single test
  activitypub-testing get test --uuid=<uuid> [--output=<mediaType>]
  # run a test
  activitypub-testing run test (--uuid=<uuid> | --slug=<slug>) --inputs.anyInputName=<inputs.anyInputName>
  activitypub-testing [--help] [-h] [help]

Options:
  -h --help        Show this help text.
  -o --output      Choose output media type (default `text`, also allows `json`, `yaml`)

Examples:
  # runs test inbox-must-be-an-orderedcollection[1] against a valid actor fetched via https
  activitypub-testing \
    test \
    --uuid '5e94d155-ed4a-4d71-b797-d7c387736ecf' \
    --inputs.object="$(curl -s 'https://socialweb.coop/activitypub/actors/with-empty-inbox.json')"

[0]: https://en.wikipedia.org/wiki/ActivityPub
[1]: https://socialweb.coop/activitypub/test-cases/inbox-must-be-an-orderedcollection/

```

`run test` by slug
```shell
⚡  npx @socialweb.coop/activitypub-testing run test --slug actor-must-serve-as2-object-to-get --inputs.time="T1M" --inputs.id="https://bengo.is/actor.json"
{
  "type": "Assertion",
  "test": {
    "id": "urn:uuid:e7ee491d-88d7-4e67-80c8-f74781bb247c",
    "uuid": "e7ee491d-88d7-4e67-80c8-f74781bb247c",
    "url": "https://socialweb.coop/activitypub/test-cases/actor-must-serve-as2-object-to-get/",
    "slug": "actor-must-serve-as2-object-to-get"
  },
  "result": {
    "outcome": "passed"
  },
  "@context": [
    "https://socialweb.coop/ns/testing/context.json"
  ]
}
```

or

`run test` by uuid
```shell
⚡ npx @socialweb.coop/activitypub-testing run test --uuid 'e7ee491d-88d7-4e67-80c8-f74781bb247c' --inputs.time="T1M" --inputs.id="https://bengo.is/404"       
{
  "type": "Assertion",
  "test": {
    "id": "urn:uuid:e7ee491d-88d7-4e67-80c8-f74781bb247c",
    "uuid": "e7ee491d-88d7-4e67-80c8-f74781bb247c",
    "url": "https://socialweb.coop/activitypub/test-cases/actor-must-serve-as2-object-to-get/",
    "slug": "actor-must-serve-as2-object-to-get"
  },
  "result": {
    "outcome": "failed",
    "info": "unable to parse response body as JSON",
    "pointer": {
      "response": {
        "body": "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body>\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/1.25.2</center>\r\n</body>\r\n</html>\r\n",
        "statusCodeValue": "404",
        "headers": []
      }
    }
  },
  "@context": [
    "https://socialweb.coop/ns/testing/context.json"
  ]
}
```

### install globally using `npm`

Or to install an `activitypub-testing` command globally for repeat usage, run:

```shell
npm install -g @socialweb.coop/activitypub-testing
```

`npm install -g` should have installed `activitypub-testing` to your shell `PATH`.
The following should work in your command prompt
```shell
activitypub-testing --help
```

## Developing this Repository

### Developing tests

See [./src/tests/](./src/tests/) for the source code.

Each ActivityPub test case should be in a folder in that directory named after the test slug, e.g. [./tests/actor-must-serve-as2-object-to-get](./tests/actor-must-serve-as2-object-to-get/)

### Developing the `activitypub-testing` CLI

See [./src/cli.js](./src/cli.js) for the source code.

You should be able to run the `cli.js` script like
```shell
⚡  ./src/cli.js --uuid=test-uuid
no test found with uuid of test-uuid
```

### npm scripts

These are in ./package.json and each has a name. Run like `pnpm run <name>`

* `build` - build the source code into `./dist`
* `lint` - check source code against lint rules
* `activitypub-testing` - run the `activitypub-testing` CLI
