Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reverse-chronological ordering to outbox items #34

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions features/outbox.feature

This file was deleted.

14 changes: 0 additions & 14 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
@@ -360,17 +360,3 @@ Then('{string} is in our Followers once only', async function (actorName) {

assert.equal(found.length, 1);
});

When('the contents of the outbox is requested', async function () {
const response = await fetch('http://activitypub-testing:8083/.ghost/activitypub/outbox/index', {
headers: {
'Content-Type': 'application/ld+json'
},
});

this.response = await response.json();
});

Then('the outbox contains {int} activity', function (count) {
assert.equal(this.response.totalItems, count);
});
2 changes: 1 addition & 1 deletion src/dispatchers.ts
Original file line number Diff line number Diff line change
@@ -422,7 +422,7 @@ export async function outboxDispatcher(
}
}
return {
items,
items: items.reverse(),
};
}

75 changes: 74 additions & 1 deletion src/dispatchers.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from 'assert';
import sinon from 'sinon';
import {
actorDispatcher,
keypairDispatcher,
@@ -18,7 +19,7 @@ import {
acceptDispatcher,
createDispatcher,
} from './dispatchers';
import { RequestContext } from '@fedify/fedify';
import { Activity, RequestContext } from '@fedify/fedify';
import { ACTOR_DEFAULT_HANDLE } from './constants';

describe('dispatchers', function () {
@@ -35,4 +36,76 @@ describe('dispatchers', function () {
});
describe('keypairDispatcher', function () {});
describe('handleFollow', function () {});

describe('outboxDispatcher', function () {
const outboxActivities: Record<string, any> = {
'https://example.com/create/123': {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/data-integrity/v1',
],
id: 'https://example.com/create/123',
type: 'Create',
},
'https://example.com/announce/456': {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/data-integrity/v1',
],
type: 'Announce',
id: 'https://example.com/announce/456',
},
'https://example.com/accept/789': {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/data-integrity/v1',
],
type: 'Accept',
id: 'https://example.com/accept/789',
},
'https://example.com/like/987': {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/data-integrity/v1',
],
type: 'Like',
id: 'https://example.com/like/987',
},
};

const ctx = {
data: {
db: {
get: sinon.stub(),
},
globaldb: {
get: sinon.stub(),
},
},
} as RequestContext<any>;

beforeEach(function () {
ctx.data.db.get.withArgs(['outbox']).resolves(Object.keys(outboxActivities));

Object.keys(outboxActivities).forEach(key => {
ctx.data.globaldb.get.withArgs([key]).resolves(outboxActivities[key]);
});
});

it('returns relevant items from the outbox in the correct order', async function () {
const result = await outboxDispatcher(ctx, ACTOR_DEFAULT_HANDLE);

// Check items exist
assert.ok(result.items);

// Check correct items are returned in the correct order
assert.equal(result.items.length, 2);
assert.equal(result.items[0] instanceof Activity, true);
assert.equal(result.items[1] instanceof Activity, true);
// @ts-ignore: We know that this is the correct type because of the above assertions
assert.equal(result.items[0].id.toString(), 'https://example.com/announce/456');
// @ts-ignore: We know that this is the correct type because of the above assertions
assert.equal(result.items[1].id.toString(), 'https://example.com/create/123');
});
});
});