From 8eeb7da1869c9c7387c199b905095c3445fde811 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Mon, 5 Mar 2018 22:36:54 -0800 Subject: [PATCH] getting closer --- bin/mastodon-data.js | 73 +++++++++++++++---------- bin/restore-mastodon-data.js | 8 ++- routes/_api/media.js | 3 +- routes/_api/statuses.js | 10 ++++ tests/spec/09-threads.js | 4 +- tests/spec/10-focus.js | 2 +- tests/spec/11-reblog-favorites-count.js | 8 +-- 7 files changed, 69 insertions(+), 39 deletions(-) diff --git a/bin/mastodon-data.js b/bin/mastodon-data.js index 11b68020..5896ec18 100644 --- a/bin/mastodon-data.js +++ b/bin/mastodon-data.js @@ -12,6 +12,10 @@ export const actions = times(30, i => ({ text: 'hello world' } }, + { + user: 'admin', + follow: 'foobar' + }, { user: 'admin', post: { @@ -19,6 +23,10 @@ export const actions = times(30, i => ({ privacy: 'unlisted' } }, + { + user: 'quux', + follow: 'foobar' + }, { user: 'foobar', post: { @@ -93,29 +101,18 @@ export const actions = times(30, i => ({ spoiler: 'kitten CW' } }, - // notifications for foobar { - user: 'admin', - follow: 'foobar' - }, - { - user: 'admin', + user: 'foobar', post: { - text: '@foobar direct', + internalId: 11, + text: 'direct', privacy: 'direct' } }, - { - user: 'quux', - follow: 'foobar' - }, - { - user: 'admin', - follow: 'quux' - }, { user: 'foobar', post: { + internalId: 10, text: 'this is followers-only', privacy: 'private' } @@ -128,6 +125,10 @@ export const actions = times(30, i => ({ privacy: 'unlisted' } }, + { + user: 'admin', + follow: 'quux' + }, { user: 'admin', post: { @@ -171,7 +172,16 @@ export const actions = times(30, i => ({ { user: 'admin', favorite: 2 - }, + } +]).concat(times(25, i => ({ + user: 'quux', + post: { + internalId: 100 + i, + text: 'unlisted thread ' + (i + 1), + privacy: 'unlisted', + inReplyTo: i > 0 && (100 + i) + } +}))).concat([ { user: 'quux', post: { @@ -187,16 +197,7 @@ export const actions = times(30, i => ({ text: 'pinned toot 2', privacy: 'unlisted' } - } -]).concat(times(25, i => ({ - user: 'quux', - post: { - internalId: 100 + i, - text: 'unlisted thread ' + (i + 1), - privacy: 'unlisted', - inReplyTo: i > 0 && (100 + i) - } -}))).concat([ + }, { user: 'quux', pin: 5 @@ -213,13 +214,29 @@ export const actions = times(30, i => ({ user: 'admin', favorite: 5 }, + { + user: 'admin', + favorite: 6 + }, { user: 'foobar', favorite: 5 }, { - user: 'admin', - favorite: 6 + user: 'foobar', + favorite: 2 + }, + { + user: 'foobar', + favorite: 10 + }, + { + user: 'foobar', + favorite: 3 + }, + { + user: 'foobar', + pin: 2 }, { user: 'ExternalLinks', diff --git a/bin/restore-mastodon-data.js b/bin/restore-mastodon-data.js index ff7fea59..b0be5d36 100644 --- a/bin/restore-mastodon-data.js +++ b/bin/restore-mastodon-data.js @@ -1,6 +1,6 @@ import { actions } from './mastodon-data' import { users } from '../tests/users' -import { postStatus } from '../routes/_api/statuses' +import { pinStatus, postStatus } from '../routes/_api/statuses' import { uploadMedia } from '../routes/_api/media' import { followAccount } from '../routes/_api/follow' import { favoriteStatus } from '../routes/_api/favorite' @@ -37,7 +37,7 @@ export async function restoreMastodonData () { type: type, buffer: await readFile(path.join(__dirname, '../tests/images/' + mediaItem)) }) - let mediaResponse = await uploadMedia('localhost:3000', accessToken, file) + let mediaResponse = await uploadMedia('localhost:3000', accessToken, file, 'kitten') return mediaResponse.id })) let status = await postStatus('localhost:3000', accessToken, text, inReplyTo, mediaIds, @@ -51,8 +51,10 @@ export async function restoreMastodonData () { await favoriteStatus('localhost:3000', accessToken, internalIdsToIds[action.favorite]) } else if (action.boost) { await reblogStatus('localhost:3000', accessToken, internalIdsToIds[action.boost]) + } else if (action.pin) { + await pinStatus('localhost:3000', accessToken, internalIdsToIds[action.pin]) } - await new Promise(resolve => setTimeout(resolve, 2000)) + await new Promise(resolve => setTimeout(resolve, 1500)) } console.log('Restored mastodon data') } \ No newline at end of file diff --git a/routes/_api/media.js b/routes/_api/media.js index c3a6c1f8..13110615 100644 --- a/routes/_api/media.js +++ b/routes/_api/media.js @@ -1,9 +1,10 @@ import { auth, basename } from './utils' import { postWithTimeout } from '../_utils/ajax' -export async function uploadMedia (instanceName, accessToken, file) { +export async function uploadMedia (instanceName, accessToken, file, description) { let formData = new FormData() formData.append('file', file) + formData.append('description', description) let url = `${basename(instanceName)}/api/v1/media` return postWithTimeout(url, formData, auth(accessToken)) } diff --git a/routes/_api/statuses.js b/routes/_api/statuses.js index 3679dd0c..0df1c1d1 100644 --- a/routes/_api/statuses.js +++ b/routes/_api/statuses.js @@ -23,3 +23,13 @@ export async function postStatus (instanceName, accessToken, text, inReplyToId, return postWithTimeout(url, body, auth(accessToken)) } + +export async function pinStatus (instanceName, accessToken, statusId) { + let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/pin` + return postWithTimeout(url, null, auth(accessToken)) +} + +export async function unpinStatus (instanceName, accessToken, statusId) { + let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/unpin` + return postWithTimeout(url, null, auth(accessToken)) +} \ No newline at end of file diff --git a/tests/spec/09-threads.js b/tests/spec/09-threads.js index 08c0ca42..56cd1356 100644 --- a/tests/spec/09-threads.js +++ b/tests/spec/09-threads.js @@ -13,7 +13,7 @@ test('Shows a thread', async t => { await scrollToBottomOfTimeline(t) await t .click(getNthStatus(26)) - .expect(getUrl()).contains('/statuses/99549257018049016') + .expect(getUrl()).contains('/statuses/') await validateTimeline(t, quuxThread) @@ -30,7 +30,7 @@ test('Scrolls to proper point in thread', async t => { .hover(getNthStatus(8)) .hover(getNthStatus(10)) .click(getNthStatus(10)) - .expect(getUrl()).contains('/statuses/99549263341916700') + .expect(getUrl()).contains('/statuses/') .expect(getNthStatus(16).innerText).contains('unlisted thread 17') .expect(Math.round(getNthStatus(16).boundingClientRect.top)) .eql(Math.round($('.container').boundingClientRect.top)) diff --git a/tests/spec/10-focus.js b/tests/spec/10-focus.js index 9b409a18..4f41c4fc 100644 --- a/tests/spec/10-focus.js +++ b/tests/spec/10-focus.js @@ -18,7 +18,7 @@ test('modal preserves focus', async t => { test('timeline preserves focus', async t => { await t.useRole(foobarRole) .click(getNthStatus(0)) - .expect(getUrl()).contains('/statuses/99549266679020981') + .expect(getUrl()).contains('/statuses/') await goBack() await t.expect(getActiveElementClass()).eql('status-article status-in-timeline') diff --git a/tests/spec/11-reblog-favorites-count.js b/tests/spec/11-reblog-favorites-count.js index bd2bd25d..374b553f 100644 --- a/tests/spec/11-reblog-favorites-count.js +++ b/tests/spec/11-reblog-favorites-count.js @@ -8,11 +8,11 @@ fixture`11-reblog-favorites-count.js` test('shows favorites', async t => { await t.useRole(foobarRole) .click(getNthStatus(0)) - .expect(getUrl()).contains('/statuses/99549266679020981') + .expect(getUrl()).contains('/statuses/') .expect(getFavoritesCount()).eql(2) .expect($('.icon-button[aria-label="Favorite"]').getAttribute('aria-pressed')).eql('true') .click($('.status-favs-reblogs').nth(1)) - .expect(getUrl()).contains('/statuses/99549266679020981/favorites') + .expect(getUrl()).match(/\/statuses\/[^\/]+\/favorites/) .expect($('.search-result-account-name').nth(0).innerText).eql('foobar') .expect($('.search-result-account-username').nth(0).innerText).eql('@foobar') .expect($('.search-result-account-name').nth(1).innerText).eql('admin') @@ -22,11 +22,11 @@ test('shows favorites', async t => { test('shows boosts', async t => { await t.useRole(foobarRole) .click(getNthStatus(0)) - .expect(getUrl()).contains('/statuses/99549266679020981') + .expect(getUrl()).contains('/statuses/') .expect(getReblogsCount()).eql(1) .expect($('.icon-button[aria-label="Boost"]').getAttribute('aria-pressed')).eql('false') .click($('.status-favs-reblogs').nth(0)) - .expect(getUrl()).contains('/statuses/99549266679020981/reblogs') + .expect(getUrl()).match(/\/statuses\/[^\/]+\/reblogs/) .expect($('.search-result-account-name').nth(0).innerText).eql('admin') .expect($('.search-result-account-username').nth(0).innerText).eql('@admin') })