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

refs #53 Add unit tests #63

Merged
merged 6 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
lib
example/typescript/dist
example/javascript/dist

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cache:
yarn: true
script:
- yarn run build
- yarn run test
5 changes: 5 additions & 0 deletions example/javascript/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
47 changes: 26 additions & 21 deletions example/javascript/authorization.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
const readline = require('readline')
const Mastodon = require( '../../lib/mastodon')
import readline from 'readline'
import Mastodon from 'megalodon'

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

const SCOPES = 'read write follow'
const BASE_URL = 'https://pleroma.io'
const BASE_URL = 'https://mastodon.social'

let clientId
let clientSecret

Mastodon.registerApp('Test App', {
scopes: SCOPES
}, BASE_URL).then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
console.log('\nclient_id:')
console.log(clientId)
console.log('\nclient_secret:')
console.log(clientSecret)
console.log('\nAuthorization URL is generated.')
console.log(appData.url)
console.log()
return new Promise(resolve => {
rl.question('Enter the authorization code from website: ', code => {
resolve(code)
rl.close()
Mastodon.registerApp(
'Test App',
{
scopes: SCOPES
},
BASE_URL
)
.then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
console.log('\nclient_id:')
console.log(clientId)
console.log('\nclient_secret:')
console.log(clientSecret)
console.log('\nAuthorization URL is generated.')
console.log(appData.url)
console.log()
return new Promise(resolve => {
rl.question('Enter the authorization code from website: ', code => {
resolve(code)
rl.close()
})
})
})
}).then(code => Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL))
.then(code => Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL))
.then(tokenData => {
console.log('\naccess_token:')
console.log(tokenData.accessToken)
Expand All @@ -39,4 +45,3 @@ Mastodon.registerApp('Test App', {
console.log()
})
.catch(err => console.error(err))

20 changes: 8 additions & 12 deletions example/javascript/favourite.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const Mastodon = require( '../../lib/mastodon')
import Mastodon from 'megalodon'

const BASE_URL = 'https://mstdn.jp'
const BASE_URL = 'https://mastodon.social'

const access_token = '...'
const access_token = process.env.MASTODON_ACCESS_TOKEN

const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const client = new Mastodon(access_token, BASE_URL + '/api/v1')

client.get('/favourites')
.then((res) => {
console.log(res.headers)
console.log(res.data)
})
client.get('/favourites').then(res => {
console.log(res.headers)
console.log(res.data)
})
14 changes: 14 additions & 0 deletions example/javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example",
"author": "h3poteto",
"scripts": {
"build": "babel -d ./dist . -s --ignore 'node_modules/**/*.js' --ignore 'dist/*'"
},
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"megalodon": "file:../../"
}
}
2 changes: 1 addition & 1 deletion example/javascript/refresh.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Please use this function after authorization.js
// Now mastodon and pleroma don't have refersh token method.
// So this example is failed.
const Mastodon = require( '../../lib/mastodon')
import Mastodon from 'megalodon'

const BASE_URL = 'https://pleroma.io'

Expand Down
4 changes: 2 additions & 2 deletions example/javascript/streaming.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Mastodon = require('../../lib/mastodon')
import Mastodon from 'megalodon'

const BASE_URL = 'https://mstdn.jp'
const BASE_URL = 'https://mastodon.social'

const access_token = process.env.MASTODON_ACCESS_TOKEN

Expand Down
4 changes: 2 additions & 2 deletions example/javascript/timeline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Mastodon = require('../../lib/mastodon')
import Mastodon from 'megalodon'

const BASE_URL = 'https://mstdn.jp'
const BASE_URL = 'https://mastodon.social'

const access_token = process.env.MASTODON_ACCESS_TOKEN

Expand Down
18 changes: 8 additions & 10 deletions example/javascript/toot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const readline = require('readline')
const Mastodon = require('../../lib/mastodon')
import readline from 'readline'
import Mastodon from 'megalodon'

const rl = readline.createInterface({
input: process.stdin,
Expand All @@ -8,17 +8,15 @@ const rl = readline.createInterface({

const BASE_URL = 'https://mastodon.social'

const access_token = '...'
const access_token = process.env.MASTODON_ACCESS_TOKEN

const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
new Promise(resolve => {
rl.question('Toot: ', status => {
client.post('/statuses', {
status: status
})
client
.post('/statuses', {
status: status
})
.then(res => {
console.log(res)
rl.close()
Expand Down
2 changes: 1 addition & 1 deletion example/javascript/web_socket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Mastodon = require('../../lib/mastodon')
import Mastodon from 'megalodon'

const BASE_URL = 'wss://pleroma.io'

Expand Down
Loading