Search Apps Documentation Source Content File Folder Download Copy

home_test.gno

2.27 Kb ยท 97 lines
 1package home
 2
 3import (
 4	"std"
 5	"testing"
 6
 7	"gno.land/p/demo/testutils"
 8)
 9
10func TestUpdateGithubUrl(t *testing.T) {
11	caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
12	std.TestSetOrigCaller(caller)
13
14	newUrl := "https://github.com/example"
15
16	UpdateGithubUrl(newUrl)
17
18	if githubUrl != newUrl {
19		t.Fatalf("GitHub url not updated properly!")
20	}
21}
22
23func TestUpdateLinkedinUrl(t *testing.T) {
24	caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
25	std.TestSetOrigCaller(caller)
26
27	newUrl := "https://www.linkedin.com/in/example"
28
29	UpdateGithubUrl(newUrl)
30
31	if githubUrl != newUrl {
32		t.Fatalf("LinkedIn url not updated properly!")
33	}
34}
35
36func TestUpdateAboutMe(t *testing.T) {
37	caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
38	std.TestSetOrigCaller(caller)
39
40	newAboutMe := "This is new description!"
41
42	UpdateAboutMe(newAboutMe)
43
44	if aboutMe != newAboutMe {
45		t.Fatalf("About mew not updated properly!")
46	}
47}
48
49func TestUpdateSelectedImage(t *testing.T) {
50	var user = testutils.TestAddress("user")
51	std.TestSetOrigCaller(user)
52
53	validImageUrl := "https://i.ibb.co/hLtmnX0/beautiful-rain-forest-ang-ka-nature-trail-doi-inthanon-national-park-thailand-36703721.webp"
54
55	coinsSent := std.NewCoins(std.NewCoin("ugnot", 5000000)) // Update to match the price expected by your function
56	std.TestSetOrigSend(coinsSent, std.NewCoins())
57
58	UpdateSelectedImage(validImageUrl)
59
60	if selectedImage != validImageUrl {
61		t.Fatalf("Valid image URL rejected!")
62	}
63
64	invalidImageUrl := "https://ibb.co/Kb3rQNn"
65
66	defer func() {
67		if r := recover(); r == nil {
68			t.Fatalf("Expected panic for invalid image URL, but got no panic")
69		}
70	}()
71
72	UpdateSelectedImage(invalidImageUrl)
73
74	invalidCoins := std.NewCoins(std.NewCoin("ugnot", 1000000))
75	std.TestSetOrigSend(invalidCoins, std.NewCoins())
76
77	defer func() {
78		if r := recover(); r == nil {
79			t.Fatalf("Expected panic for incorrect coin denomination or amount, but got no panic")
80		}
81	}()
82
83	UpdateSelectedImage(validImageUrl)
84}
85
86func TestUpdateImagePrice(t *testing.T) {
87	caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
88	std.TestSetOrigCaller(caller)
89
90	var newImageUpdatePrice int64 = 3000000
91
92	UpdateImagePrice(newImageUpdatePrice)
93
94	if imageUpdatePrice != newImageUpdatePrice {
95		t.Fatalf("Image update price not updated properly!")
96	}
97}