Compare commits
2 Commits
8346e8cd3a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ebe4868645 | |||
| c7db2be6d0 |
76
backend/utils_test.go
Normal file
76
backend/utils_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseNote(t *testing.T) {
|
||||
data := `p:Мундиль
|
||||
g:Культурные люди
|
||||
d:2024-10-30
|
||||
Worgen balance druid
|
||||
Came to orgrimmar trying to kill saurfang and killing people with <1m hp
|
||||
18:04:24 > r:Myxich
|
||||
Is very weak and scared
|
||||
Has like 7M hp but refuses to fight
|
||||
Refuses to fight anyone >1M hp that is
|
||||
Tried hiding tried flying and failed`
|
||||
note, err := ParseNote(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if note.Player != "Мундиль" {
|
||||
t.Errorf("Expected player to be Мундиль, got %s", note.Player)
|
||||
}
|
||||
if note.Guild != "Культурные люди" {
|
||||
t.Errorf("Expected guild to be Культурные люди, got %s", note.Guild)
|
||||
}
|
||||
if note.Date.Format(time.DateOnly) != "2024-10-30" {
|
||||
t.Errorf("Expected date to be 2024-10-30, got %s", note.Date.Format(time.DateOnly))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseNoteNoGuild(t *testing.T) {
|
||||
data := `p:Kulmi
|
||||
d:2024-10-30
|
||||
Came to orgrimmar trying to kill saurfang
|
||||
Also killed some weak ass paladin, obviously interested in stomping noobs
|
||||
Is one of those wpvp heroes, fully kitted out and shit`
|
||||
note, err := ParseNote(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if note.Player != "Kulmi" {
|
||||
t.Errorf("Expected player to be Kulmi, got %s", note.Player)
|
||||
}
|
||||
if note.Guild != "" {
|
||||
t.Errorf("Expected guild to be empty, got %s", note.Guild)
|
||||
}
|
||||
if note.Date.Format(time.DateOnly) != "2024-10-30" {
|
||||
t.Errorf("Expected date to be 2024-10-30, got %s", note.Date.Format(time.DateOnly))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseNoteNoDate(t *testing.T) {
|
||||
data := `p:Ashripper
|
||||
g:The Inferno
|
||||
Came to orgrimmar causing trouble
|
||||
This is Criminallad and probably Criminaldad
|
||||
There's nothing I can do to stop him and he knows it
|
||||
He is deeply rooted with THE guild`
|
||||
note, err := ParseNote(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if note.Player != "Ashripper" {
|
||||
t.Errorf("Expected player to be Ashripper, got %s", note.Player)
|
||||
}
|
||||
if note.Guild != "The Inferno" {
|
||||
t.Errorf("Expected guild to be The Inferno, got %s", note.Guild)
|
||||
}
|
||||
now := time.Now()
|
||||
if note.Date.Format(time.DateOnly) != now.Format(time.DateOnly) {
|
||||
t.Errorf("Expected date to be %s got %s", now.Format(time.DateOnly), note.Date.Format(time.DateOnly))
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ console.log(request);
|
||||
if (form) {
|
||||
form.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
const note = document.querySelector("#note");
|
||||
const note: HTMLElement | null = document.querySelector("#note");
|
||||
if (!note) {
|
||||
console.error("No note found");
|
||||
return;
|
||||
@@ -41,22 +41,22 @@ console.log(request);
|
||||
|
||||
fetch(window.location.href, {
|
||||
method: "POST",
|
||||
body: note.textContent,
|
||||
body: note.innerText,
|
||||
}).then((res) => {
|
||||
if (res.status != 200) {
|
||||
console.error(res);
|
||||
const err = res.statusText;
|
||||
const kaput = document.querySelector("#kaput");
|
||||
const kaput: HTMLElement | null = document.querySelector("#kaput");
|
||||
if (!kaput) {
|
||||
console.error("No kaput found");
|
||||
return;
|
||||
}
|
||||
kaput?.classList.remove("display-none");
|
||||
kaput.textContent = err;
|
||||
kaput.innerText = err;
|
||||
} else {
|
||||
const kaput = document.querySelector("#kaput");
|
||||
kaput?.classList.add("display-none");
|
||||
note.textContent = "";
|
||||
note.innerText = "";
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user