Files
cell-discord/tests/discord.cm
2026-01-23 15:06:54 -06:00

97 lines
3.3 KiB
Plaintext

// Discord SDK synchronous tests
// These tests check the basic API without requiring authentication
// For full integration tests with callbacks, see discord_integration.ce
var discord = use('discord')
// Test application ID (Tangle Tart)
def TEST_APP_ID = "1446585686789586975"
return {
// Test that the module loads correctly
test_module_loads: function() {
if (!is_object(discord)) throw "Discord module should be an object"
if (!is_function(discord.init)) throw "discord.init should be a function"
if (!is_function(discord.run_callbacks)) throw "discord.run_callbacks should be a function"
if (!is_function(discord.shutdown)) throw "discord.shutdown should be a function"
},
// Test initialization
test_init: function() {
var result = discord.init(TEST_APP_ID)
if (!result) throw "discord.init should return true on success"
},
// Test status before connection
test_status_before_connect: function() {
var status = discord.get_status()
// Should be disconnected since we haven't connected yet
if (status != "disconnected" && status != "not_initialized") {
throw `Expected disconnected status, got: ${status}`
}
},
// Test is_authenticated before auth
test_not_authenticated: function() {
var auth = discord.is_authenticated()
if (auth) throw "Should not be authenticated before auth flow"
},
// Test get_default_scopes
test_get_default_scopes: function() {
var scopes = discord.get_default_scopes()
if (!scopes || scopes.length == 0) throw "Default scopes should not be empty"
log.console(`Default scopes: ${scopes}`)
},
// Test get_current_user before auth (should return null)
test_get_user_before_auth: function() {
var user = discord.get_current_user()
// Should be null since we're not authenticated
if (user != null) {
log.console("Note: User returned before auth - may be cached from previous session")
}
},
// Test get_relationships before auth
test_get_relationships_before_auth: function() {
var rels = discord.get_relationships()
if (!Array.isArray(rels)) throw "get_relationships should return an array"
log.console(`Relationships count: ${rels.length}`)
},
// Test callback registration
test_callback_registration: function() {
// These should not throw
discord.on_status_changed(function(status, error, detail) {
log.console(`Status: ${status}`)
})
discord.on_log(function(msg, severity) {
log.console(`[${severity}] ${msg}`)
}, "info")
// Clear callbacks
discord.on_status_changed(null)
discord.on_log(null)
},
// Test run_callbacks (should not throw even without connection)
test_run_callbacks: function() {
discord.run_callbacks()
},
// Test clear_rich_presence (should not throw)
test_clear_rich_presence: function() {
discord.clear_rich_presence()
},
// Test shutdown
test_shutdown: function() {
discord.shutdown()
var status = discord.get_status()
if (status != "not_initialized") {
throw `Expected not_initialized after shutdown, got: ${status}`
}
}
}