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
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'
|
||
|
|
||
|
export async function testLoginAndOut() {
|
||
|
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
|
||
|
}
|
||
|
|
||
|
export async function runAllTests() {
|
||
|
await testLoginAndOut()
|
||
|
}
|
||
|
|
||
|
export const testDict = {
|
||
|
"Run All Tests": runAllTests,
|
||
|
"Test Login/Logout": testLoginAndOut
|
||
|
}
|