---

type:
- TestCase
tags:
- tests-activitypub-object
uuid:
- 200b9bc8-aae3-46f2-a6ab-5366042c0f6e

respec:
  config:
    editors:
    - name: bengo
      url: "https://bengo.is"
      w3cid: 49026
---

# An ActivityPub Object `likes` Collection Must be a Collection

## Background

[ActivityPub][activitypub] says
> Every object MAY have a likes collection.
> &hellip;
> The likes collection MUST be either an OrderedCollection or a Collection

## About This Test

This is a Test Case describing a rule to determine whether an ActivityPub Object is in partial conformance with the following behaviors required by [ActivityPub][activitypub].

* [requirement f965e989-4084-4f9d-9119-6a7ea13bcb64](https://socialweb.coop/activitypub/behaviors/f965e989-4084-4f9d-9119-6a7ea13bcb64/) - The likes collection MUST be either an OrderedCollection or a Collection

### Identifier

The identifier of this test is `urn:uuid:200b9bc8-aae3-46f2-a6ab-5366042c0f6e`.

## Test Subject

The subject of this test is an ActivityPub Object.

## Input

This test requires the following [inputs](act-rules-input) indicating parts of the test subject:

### `input.object`

the object whose `likes` property will be tested

* type: binary
* constraints
    * should be JSON

## Applicability

This test applies to each of the likes collections derived from the values of the property on `object` named `likes`.

### Prerequisites

* `object` is a JSON object
* `object` JSON object has a property named `likes`

### Test Targets

How to Derive Test Targets from Input

* let `targets` be a set
* let `likesValues` be the result of
    * if `object.likes` is an Array, return it
    * else return an Array whose only item is the value of `object.likes`
* for each item in `likesValues`
    * if item is a string
        * let itemFetched be the result of interpreting the string as an ActivityPub Object Identifier and fetching the corresponding ActivityPub Object.
        * add itemFetched to `targets`
    * else add item to `targets`
* return `targets`

## Expectations

For every target `target`

* `target` is a JSON object
* `target` has a property named `type`
* the value of the `target`'s `type` property must be one of
    * an array containing the string "Collection"
    * an array containing the string "OrderedCollection"
    * the string "Collection"
    * the string "OrderedCollection"

## Test Cases

What follows are some specific cases of applything this test rule.

### Passed Example 1

inputs

* `object`:

  ```json
  {
    "likes": {
      "type": "Collection"
    }
  }
  ```

test targets

* ```json
  {
    "type": "Collection"
  }
  ```

    * outcome: `passed`

### Passed Example 2

inputs

* `object`:

  ```json
  {
    "likes": {
      "type": "OrderedCollection"
    }
  }
  ```

test targets

* ```json
  {
    "type": "OrderedCollection"
  }
  ```

    * outcome: `passed`

### Passed Example 3

inputs

* `object`:

  ```json
  {
    "likes": {
      "type": ["FancyCollection", "OrderedCollection"]
    }
  }
  ```

test targets

* ```json
  {
    "likes": {
      "type": ["FancyCollection", "OrderedCollection"]
    }
  }
  ```

    * outcome: `passed`
        * rationale: `"FancyCollection"` is not well-defined here, but this object still passes the test because at least one of the `type` property values is `OrderedCollection` and thus satisfies the requirement as interpreted.

### Failed Example 1 - Likes is a number

inputs

* `object`:

  ```json
  {
    "likes": 1
  }
  ```

test targets

* ```json
  1
  ```

    * outcome: `failed`

### Failed Example 2 - Likes is an empty object

inputs

* `object`:

  ```json
  {
    "likes": {}
  }
  ```

test targets

* ```json
  {}
  ```

    * outcome: `failed`

### Failed Example 3 - Likes object type is array including only `"Link"`

inputs

* `object`:

  ```json
  {
    "likes": {
      "type": ["Link"]
    }
  }
  ```

test targets

* ```json
  {
    "type": ["Link"]
  }
  ```

    * outcome: `failed`

### Inapplicable Example 1

inputs

* `object`:

  ```json
  1
  ```

result

* outcome: `inapplicable`

### Inapplicable Example 2 - object has no likes property

inputs

* `object`:

  ```json
  { "foo": "bar" }
  ```

result

* outcome: `inapplicable`

### Inapplicable Example 3 - object is html

inputs

* `object`:

  ```html
  <!doctype html>hi
  ```

result

* outcome: `inapplicable`

## Glossary [<sup>?</sup>](https://www.w3.org/TR/act-rules-format/#glossary)

### `outcome`

An outcome is a conclusion that comes from evaluating a test on a test subject. An outcome can be one of the three following types:

* `inapplicable`: No part of the test subject matches the applicability
* `passed`: A test target meets all expectations
* `failed`: A test target does not meet all expectations

## Requirements Mapping [<sup>?</sup>](https://www.w3.org/TR/act-rules-format/#accessibility-requirements-mapping)

* [ActivityPub requirement f965e989-4084-4f9d-9119-6a7ea13bcb64](https://socialweb.coop/activitypub/behaviors/f965e989-4084-4f9d-9119-6a7ea13bcb64/) - The likes collection MUST be either an OrderedCollection or a Collection
    * Required for Conformance to [ActivityPub][activitypub]
    * Outcome Mapping
        * when every test target has outcome `passed`, the requirement is satisfied by the test subject
        * when any test target has outcome `failed`, the requirement is not satisfied by the test subject
        * when any test target has outcome `inapplicable`, further testing is needed to determine requirement satisfaction

## Issues [<sup>?</sup>](https://www.w3.org/TR/act-rules-format/issues-list)

## Change Log

* 2023-12-06T06:48:14.689Z: init
* 2023-12-18T04:33:22.670Z: add more example cases that were useful for maximizing implementation code coverage

[activitypub]: https://www.w3.org/TR/activitypub/
