pinafore/tests/serverActions.js

100 lines
3.8 KiB
JavaScript
Raw Normal View History

import { favoriteStatus } from '../src/routes/_api/favorite'
2018-02-25 05:27:32 +00:00
import fetch from 'node-fetch'
2018-03-10 18:54:16 +00:00
import FileApi from 'file-api'
import { users } from './users'
import { postStatus } from '../src/routes/_api/statuses'
import { deleteStatus } from '../src/routes/_api/delete'
import { authorizeFollowRequest, getFollowRequests } from '../src/routes/_api/followRequests'
import { followAccount, unfollowAccount } from '../src/routes/_api/follow'
import { updateCredentials } from '../src/routes/_api/updateCredentials'
import { reblogStatus } from '../src/routes/_api/reblog'
import { submitMedia } from './submitMedia'
import { voteOnPoll } from '../src/routes/_api/polls'
import { POLL_EXPIRY_DEFAULT } from '../src/routes/_static/polls'
import { createList, getLists } from '../src/routes/_api/lists'
2018-03-10 18:54:16 +00:00
2018-03-06 07:56:48 +00:00
global.fetch = fetch
2018-03-10 18:54:16 +00:00
global.File = FileApi.File
global.FormData = FileApi.FormData
2018-02-25 05:27:32 +00:00
2018-03-11 00:21:10 +00:00
const instanceName = 'localhost:3000'
2018-03-16 17:06:02 +00:00
export async function favoriteStatusAs (username, statusId) {
return favoriteStatus(instanceName, users[username].accessToken, statusId)
2018-02-25 05:27:32 +00:00
}
2018-03-10 18:54:16 +00:00
export async function reblogStatusAs (username, statusId) {
return reblogStatus(instanceName, users[username].accessToken, statusId)
}
2018-03-16 17:06:02 +00:00
export async function postAs (username, text) {
return postStatus(instanceName, users[username].accessToken, text,
2018-03-10 18:54:16 +00:00
null, null, false, null, 'public')
}
2018-03-11 00:21:10 +00:00
export async function postWithSpoilerAndPrivacyAs (username, text, spoiler, privacy) {
return postStatus(instanceName, users[username].accessToken, text,
null, null, true, spoiler, privacy)
}
export async function postStatusWithMediaAs (username, status, filename, alt, sensitive) {
const mediaResponse = await submitMedia(users[username].accessToken, filename, alt)
return postStatus(instanceName, users[username].accessToken, status,
null, [mediaResponse.id], !!sensitive, null, 'public')
}
export async function postEmptyStatusWithMediaAs (username, filename, alt, sensitive) {
2019-08-03 20:49:37 +00:00
const mediaResponse = await submitMedia(users[username].accessToken, filename, alt)
return postStatus(instanceName, users[username].accessToken, '',
null, [mediaResponse.id], !!sensitive, null, 'public')
}
2018-03-16 17:06:02 +00:00
export async function postReplyAs (username, text, inReplyTo) {
return postStatus(instanceName, users[username].accessToken, text,
inReplyTo, null, false, null, 'public')
}
2018-03-16 17:06:02 +00:00
export async function deleteAs (username, statusId) {
return deleteStatus(instanceName, users[username].accessToken, statusId)
2018-03-11 00:21:10 +00:00
}
2018-03-15 05:14:06 +00:00
2018-03-16 17:06:02 +00:00
export async function getFollowRequestsAs (username) {
return getFollowRequests(instanceName, users[username].accessToken)
2018-03-15 05:14:06 +00:00
}
2018-03-16 17:06:02 +00:00
export async function authorizeFollowRequestAs (username, id) {
return authorizeFollowRequest(instanceName, users[username].accessToken, id)
2018-03-15 05:14:06 +00:00
}
export async function followAs (username, userToFollow) {
return followAccount(instanceName, users[username].accessToken, users[userToFollow].id)
}
export async function unfollowAs (username, userToFollow) {
return unfollowAccount(instanceName, users[username].accessToken, users[userToFollow].id)
}
export async function updateUserDisplayNameAs (username, displayName) {
return updateCredentials(instanceName, users[username].accessToken, { display_name: displayName })
}
export async function createPollAs (username, content, options, multiple, spoilerText) {
return postStatus(instanceName, users[username].accessToken, content, null, null, false, spoilerText, 'public', {
options,
multiple,
expires_in: POLL_EXPIRY_DEFAULT
})
}
export async function voteOnPollAs (username, pollId, choices) {
return voteOnPoll(instanceName, users[username].accessToken, pollId, choices.map(_ => _.toString()))
}
export async function createListAs (username, title) {
return createList(instanceName, users[username].accessToken, title)
}
export async function getListsAs (username) {
return getLists(instanceName, users[username].accessToken)
}