2018-12-11 07:31:48 -08:00
|
|
|
import { favoriteStatus } from '../src/routes/_api/favorite'
|
2018-02-24 21:27:32 -08:00
|
|
|
import fetch from 'node-fetch'
|
2018-03-10 10:54:16 -08:00
|
|
|
import FileApi from 'file-api'
|
2018-03-05 20:29:49 -08:00
|
|
|
import { users } from './users'
|
2018-12-11 07:31:48 -08:00
|
|
|
import { postStatus } from '../src/routes/_api/statuses'
|
|
|
|
import { deleteStatus } from '../src/routes/_api/delete'
|
|
|
|
import { authorizeFollowRequest, getFollowRequests } from '../src/routes/_actions/followRequests'
|
|
|
|
import { followAccount, unfollowAccount } from '../src/routes/_api/follow'
|
|
|
|
import { updateCredentials } from '../src/routes/_api/updateCredentials'
|
|
|
|
import { reblogStatus } from '../src/routes/_api/reblog'
|
2018-12-01 00:10:30 -08:00
|
|
|
import { submitMedia } from './submitMedia'
|
2019-05-27 12:31:35 -07:00
|
|
|
import { voteOnPoll } from '../src/routes/_api/polls'
|
|
|
|
import { POLL_EXPIRY_DEFAULT } from '../src/routes/_static/polls'
|
2018-03-10 10:54:16 -08:00
|
|
|
|
2018-03-05 23:56:48 -08:00
|
|
|
global.fetch = fetch
|
2018-03-10 10:54:16 -08:00
|
|
|
global.File = FileApi.File
|
|
|
|
global.FormData = FileApi.FormData
|
2018-02-24 21:27:32 -08:00
|
|
|
|
2018-03-10 16:21:10 -08:00
|
|
|
const instanceName = 'localhost:3000'
|
|
|
|
|
2018-03-16 10:06:02 -07:00
|
|
|
export async function favoriteStatusAs (username, statusId) {
|
|
|
|
return favoriteStatus(instanceName, users[username].accessToken, statusId)
|
2018-02-24 21:27:32 -08:00
|
|
|
}
|
2018-03-10 10:54:16 -08:00
|
|
|
|
2018-08-28 06:45:15 -07:00
|
|
|
export async function reblogStatusAs (username, statusId) {
|
|
|
|
return reblogStatus(instanceName, users[username].accessToken, statusId)
|
|
|
|
}
|
|
|
|
|
2018-03-16 10:06:02 -07:00
|
|
|
export async function postAs (username, text) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
2018-03-10 10:54:16 -08:00
|
|
|
null, null, false, null, 'public')
|
|
|
|
}
|
2018-03-10 16:21:10 -08:00
|
|
|
|
2018-12-03 23:23:29 -08:00
|
|
|
export async function postWithSpoilerAndPrivacyAs (username, text, spoiler, privacy) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
|
|
|
null, null, true, spoiler, privacy)
|
|
|
|
}
|
|
|
|
|
2018-12-01 00:10:30 -08:00
|
|
|
export async function postEmptyStatusWithMediaAs (username, filename, alt) {
|
|
|
|
let mediaResponse = await submitMedia(users[username].accessToken, filename, alt)
|
|
|
|
return postStatus(instanceName, users[username].accessToken, '',
|
|
|
|
null, [mediaResponse.id], false, null, 'public')
|
|
|
|
}
|
|
|
|
|
2018-03-16 10:06:02 -07:00
|
|
|
export async function postReplyAs (username, text, inReplyTo) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
2018-03-10 20:24:07 -08:00
|
|
|
inReplyTo, null, false, null, 'public')
|
|
|
|
}
|
|
|
|
|
2018-03-16 10:06:02 -07:00
|
|
|
export async function deleteAs (username, statusId) {
|
|
|
|
return deleteStatus(instanceName, users[username].accessToken, statusId)
|
2018-03-10 16:21:10 -08:00
|
|
|
}
|
2018-03-14 22:14:06 -07:00
|
|
|
|
2018-03-16 10:06:02 -07:00
|
|
|
export async function getFollowRequestsAs (username) {
|
|
|
|
return getFollowRequests(instanceName, users[username].accessToken)
|
2018-03-14 22:14:06 -07:00
|
|
|
}
|
|
|
|
|
2018-03-16 10:06:02 -07:00
|
|
|
export async function authorizeFollowRequestAs (username, id) {
|
|
|
|
return authorizeFollowRequest(instanceName, users[username].accessToken, id)
|
2018-03-14 22:14:06 -07:00
|
|
|
}
|
2018-04-28 14:19:39 -07: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)
|
|
|
|
}
|
2018-08-19 15:23:40 -07:00
|
|
|
|
|
|
|
export async function updateUserDisplayNameAs (username, displayName) {
|
2018-08-29 21:42:57 -07:00
|
|
|
return updateCredentials(instanceName, users[username].accessToken, { display_name: displayName })
|
2018-08-19 15:23:40 -07:00
|
|
|
}
|
2019-05-27 12:31:35 -07:00
|
|
|
|
|
|
|
export async function createPollAs (username, content, options, multiple) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, content, null, null, false, null, '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()))
|
|
|
|
}
|