2024-11-03 09:45:51 -05:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-11-19 09:55:57 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-11-03 09:45:51 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const getTalkgroupWithLearnedTest = `-- name: GetTalkgroupWithLearned :one
|
|
|
|
SELECT
|
2024-11-19 09:55:57 -05:00
|
|
|
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, sys.id, sys.name
|
2024-11-03 09:45:51 -05:00
|
|
|
FROM talkgroups tg
|
|
|
|
JOIN systems sys ON tg.system_id = sys.id
|
2024-11-19 09:55:57 -05:00
|
|
|
WHERE (tg.system_id, tg.tgid) = ($1, $2) AND tg.learned IS NOT TRUE
|
2024-11-03 09:45:51 -05:00
|
|
|
UNION
|
|
|
|
SELECT
|
2024-11-19 09:55:57 -05:00
|
|
|
tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name,
|
|
|
|
tgl.alpha_tag, tgl.tg_group, NULL::INTEGER, NULL::JSONB,
|
|
|
|
CASE WHEN tgl.tg_group IS NULL THEN NULL ELSE ARRAY[tgl.tg_group] END,
|
|
|
|
TRUE, NULL::JSONB, 1.0, TRUE learned, sys.id, sys.name
|
2024-11-03 09:45:51 -05:00
|
|
|
FROM talkgroups_learned tgl
|
|
|
|
JOIN systems sys ON tgl.system_id = sys.id
|
|
|
|
WHERE tgl.system_id = $1 AND tgl.tgid = $2 AND ignored IS NOT TRUE
|
|
|
|
`
|
|
|
|
|
2024-11-04 23:41:52 -05:00
|
|
|
const getTalkgroupsWithLearnedBySystemTest = `-- name: GetTalkgroupsWithLearnedBySystem :many
|
|
|
|
SELECT
|
2024-11-19 09:55:57 -05:00
|
|
|
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, sys.id, sys.name
|
2024-11-04 23:41:52 -05:00
|
|
|
FROM talkgroups tg
|
|
|
|
JOIN systems sys ON tg.system_id = sys.id
|
2024-11-19 09:55:57 -05:00
|
|
|
WHERE tg.system_id = $1 AND tg.learned IS NOT TRUE
|
2024-11-04 23:41:52 -05:00
|
|
|
UNION
|
|
|
|
SELECT
|
2024-11-19 09:55:57 -05:00
|
|
|
tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name,
|
|
|
|
tgl.alpha_tag, tgl.tg_group, NULL::INTEGER, NULL::JSONB,
|
|
|
|
CASE WHEN tgl.tg_group IS NULL THEN NULL ELSE ARRAY[tgl.tg_group] END,
|
|
|
|
TRUE, NULL::JSONB, 1.0, TRUE learned, sys.id, sys.name
|
2024-11-04 23:41:52 -05:00
|
|
|
FROM talkgroups_learned tgl
|
|
|
|
JOIN systems sys ON tgl.system_id = sys.id
|
2024-11-12 08:40:56 -05:00
|
|
|
WHERE tgl.system_id = $1 AND ignored IS NOT TRUE
|
2024-11-04 23:41:52 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
const getTalkgroupsWithLearnedTest = `-- name: GetTalkgroupsWithLearned :many
|
|
|
|
SELECT
|
2024-11-19 09:55:57 -05:00
|
|
|
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, sys.id, sys.name
|
2024-11-04 23:41:52 -05:00
|
|
|
FROM talkgroups tg
|
|
|
|
JOIN systems sys ON tg.system_id = sys.id
|
2024-11-19 09:55:57 -05:00
|
|
|
WHERE tg.learned IS NOT TRUE
|
2024-11-04 23:41:52 -05:00
|
|
|
UNION
|
|
|
|
SELECT
|
2024-11-19 09:55:57 -05:00
|
|
|
tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name,
|
|
|
|
tgl.alpha_tag, tgl.tg_group, NULL::INTEGER, NULL::JSONB,
|
|
|
|
CASE WHEN tgl.tg_group IS NULL THEN NULL ELSE ARRAY[tgl.tg_group] END,
|
|
|
|
TRUE, NULL::JSONB, 1.0, TRUE learned, sys.id, sys.name
|
2024-11-04 23:41:52 -05:00
|
|
|
FROM talkgroups_learned tgl
|
|
|
|
JOIN systems sys ON tgl.system_id = sys.id
|
|
|
|
WHERE ignored IS NOT TRUE
|
|
|
|
`
|
|
|
|
|
2024-11-03 09:45:51 -05:00
|
|
|
func TestQueryColumnsMatch(t *testing.T) {
|
2024-11-19 09:55:57 -05:00
|
|
|
assert.Equal(t, getTalkgroupWithLearnedTest, getTalkgroupWithLearned)
|
|
|
|
assert.Equal(t, getTalkgroupsWithLearnedBySystemTest, getTalkgroupsWithLearnedBySystem)
|
|
|
|
assert.Equal(t, getTalkgroupsWithLearnedTest, getTalkgroupsWithLearned)
|
2024-11-03 09:45:51 -05:00
|
|
|
}
|