1
0
Fork 0
out-of-your-element-fork-th.../db/orm.test.js

47 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-09-18 13:23:52 +00:00
// @ts-check
const {test} = require("supertape")
const data = require("../test/data")
const {db, select, from} = require("../passthrough")
test("orm: select: get works", t => {
2023-10-05 23:31:10 +00:00
const row = select("guild_space", "guild_id", {}, "WHERE space_id = ?").get("!jjWAGMeQdNrVZSSfvz:cadence.moe")
2023-09-18 13:23:52 +00:00
t.equal(row?.guild_id, data.guild.general.id)
})
test("orm: from: get works", t => {
const row = from("guild_space").select("guild_id").and("WHERE space_id = ?").get("!jjWAGMeQdNrVZSSfvz:cadence.moe")
t.equal(row?.guild_id, data.guild.general.id)
})
test("orm: select: get pluck works", t => {
2023-10-05 23:31:10 +00:00
const guildID = select("guild_space", "guild_id", {}, "WHERE space_id = ?").pluck().get("!jjWAGMeQdNrVZSSfvz:cadence.moe")
2023-09-18 13:23:52 +00:00
t.equal(guildID, data.guild.general.id)
})
2023-10-05 23:31:10 +00:00
test("orm: select: get, where and pluck works", t => {
const channelID = select("message_channel", "channel_id", {message_id: "1128118177155526666"}).pluck().get()
t.equal(channelID, "112760669178241024")
})
test("orm: select: all, where and pluck works on multiple columns", t => {
const names = select("member_cache", "displayname", {room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", mxid: "@cadence:cadence.moe"}).pluck().all()
t.deepEqual(names, ["cadence [they]"])
})
2023-09-18 13:23:52 +00:00
test("orm: from: get pluck works", t => {
const guildID = from("guild_space").pluck("guild_id").and("WHERE space_id = ?").get("!jjWAGMeQdNrVZSSfvz:cadence.moe")
t.equal(guildID, data.guild.general.id)
})
test("orm: from: join and pluck works", t => {
2023-10-04 23:32:05 +00:00
const mxid = from("sim").join("sim_member", "mxid").and("WHERE user_id = ? AND room_id = ?").pluck("mxid").get("771520384671416320", "!hYnGGlPHlbujVVfktC:cadence.moe")
2023-09-18 13:23:52 +00:00
t.equal(mxid, "@_ooye_bojack_horseman:cadence.moe")
})
2023-10-05 23:31:10 +00:00
test("orm: from: where and pluck works", t => {
const subtypes = from("event_message").where({message_id: "1141501302736695316"}).pluck("event_subtype").all()
t.deepEqual(subtypes.sort(), ["m.image", "m.text"])
})