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.
49 lines
1.5 KiB
49 lines
1.5 KiB
// 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 { createSession, logout } from './api.js' |
|
|
|
async function testLoginAndOut() { |
|
const username = 'ao' |
|
const password = 'ao' |
|
try { |
|
console.log('Attempting login as', username, 'with password', '*'.repeat(password.length)) |
|
const response = await 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 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() { |
|
await testLoginAndOut() |
|
} |
|
|
|
export const tests = { |
|
"Run All Tests": runAllTests, |
|
"Test Login/Logout": testLoginAndOut |
|
}
|
|
|