An interactive command-line interface (CLI) tool to help you install, use, and administer an AO instance.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

3 years ago
// Unit tests for the AO
// The tests actually happen so your database will be modified (future: allow switching databases or automatically switch)
// The tests use an AO API file saved in the same directory; this file must be kept up-to-date
// Maybe in the future a precompiled api.js created from api.ts can be hosted so that ao-cli does not have to compile any TypeScript
import api from './api.js'
async function testLoginAndOut() {
3 years ago
const username = 'ao'
const password = 'ao'
try {
console.log('Attempting login as', username, 'with password', '*'.repeat(password.length))
const response = await api.createSession(username, password)
if(response === true) {
console.log('Logged in as', username)
} else {
console.log('Login failed. Response:', response)
return false
}
} catch(err) {
if(err.status === 401) {
console.log("No account on the AO server matched the username and password you entered. (401 Unauthorized)")
} else {
console.log(err)
}
}
try {
console.log('Logging out...')
const response = await api.logout()
if(response.statusCode === 200) {
console.log('Logged out')
} else {
console.log('Logout failed. Response:', response)
return false
}
} catch(err) {
console.log(err)
}
return true
}
async function runAllTests() {
3 years ago
await testLoginAndOut()
}
export const tests = {
3 years ago
"Run All Tests": runAllTests,
"Test Login/Logout": testLoginAndOut
}