Best Venom code snippet using http.New
rules_controller_test.go
Source:rules_controller_test.go
...14)15func TestListContent(t *testing.T) {16 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)17 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)18 e := echo.New()19 req := httptest.NewRequest(http.MethodGet, "/", nil)20 rec := httptest.NewRecorder()21 c := e.NewContext(req, rec)22 c.SetPath("/rule/list/:kind")23 c.SetParamNames("kind")24 c.SetParamValues("background")25 // Assertions26 if assert.NoError(t, ListContent(c)) {27 assert.Equal(t, http.StatusOK, rec.Code)28 }29 req1 := httptest.NewRequest(http.MethodGet, "/", nil)30 rec1 := httptest.NewRecorder()31 c1 := e.NewContext(req1, rec1)32 c1.SetPath("/rule/list/:kind")33 c1.SetParamNames("kindy")34 c1.SetParamValues("background")35 // Assertions36 if assert.NoError(t, ListContent(c1)) {37 assert.Equal(t, http.StatusNotImplemented, rec1.Code)38 }39}40func TestGetDescription(t *testing.T) {41 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)42 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)43 e := echo.New()44 req := httptest.NewRequest(http.MethodGet, "/", nil)45 rec := httptest.NewRecorder()46 c := e.NewContext(req, rec)47 c.SetPath("/rule/description/:kind/:name")48 c.SetParamNames("kind", "name")49 c.SetParamValues("background", "soldier")50 // Assertions51 if assert.NoError(t, GetDescription(c)) {52 assert.Equal(t, http.StatusOK, rec.Code)53 }54 req1 := httptest.NewRequest(http.MethodGet, "/", nil)55 rec1 := httptest.NewRecorder()56 c1 := e.NewContext(req1, rec1)57 c1.SetPath("/rule/description/:kind/:name")58 c1.SetParamNames("kindy", "name")59 c1.SetParamValues("background", "soldier")60 // Assertions61 if assert.NoError(t, GetDescription(c1)) {62 assert.Equal(t, http.StatusNotImplemented, rec1.Code)63 }64}65func TestGetCondition(t *testing.T) {66 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)67 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)68 e := echo.New()69 req := httptest.NewRequest(http.MethodGet, "/", nil)70 rec := httptest.NewRecorder()71 c := e.NewContext(req, rec)72 c.SetPath("/rule/condition/:name")73 c.SetParamNames("name")74 c.SetParamValues("blinded")75 // Assertions76 if assert.NoError(t, GetCondition(c)) {77 assert.Equal(t, http.StatusOK, rec.Code)78 }79 req1 := httptest.NewRequest(http.MethodGet, "/", nil)80 rec1 := httptest.NewRecorder()81 c1 := e.NewContext(req1, rec1)82 c1.SetPath("/rule/condition/:name")83 c1.SetParamNames("name")84 c1.SetParamValues("crazy")85 // Assertions86 if assert.NoError(t, GetCondition(c1)) {87 assert.Equal(t, http.StatusBadRequest, rec1.Code)88 }89 //90 req2 := httptest.NewRequest(http.MethodGet, "/", nil)91 rec2 := httptest.NewRecorder()92 c2 := e.NewContext(req2, rec2)93 c2.SetPath("/rule/condition/:name/:level")94 c2.SetParamNames("name", "level")95 c2.SetParamValues("exhaustion", "severe")96 // Assertions97 if assert.NoError(t, GetCondition(c2)) {98 assert.Equal(t, http.StatusBadRequest, rec2.Code)99 }100 req3 := httptest.NewRequest(http.MethodGet, "/", nil)101 rec3 := httptest.NewRecorder()102 c3 := e.NewContext(req3, rec3)103 c3.SetPath("/rule/condition/:name/:level")104 c3.SetParamNames("name", "level")105 c3.SetParamValues("exhaustion", "7")106 // Assertions107 if assert.NoError(t, GetCondition(c3)) {108 assert.Equal(t, http.StatusBadRequest, rec3.Code)109 }110}111// func TestCheckRoll(t *testing.T) {}112func TestGetJSON(t *testing.T) {113 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)114 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)115 e := echo.New()116 list := []string{"class", "classes", "race", "races", "background", "backgrounds", "skill", "skills"}117 for _, v := range list {118 req := httptest.NewRequest(http.MethodGet, "/", nil)119 rec := httptest.NewRecorder()120 c := e.NewContext(req, rec)121 c.SetPath("/rule/:kind")122 c.SetParamNames("kind")123 c.SetParamValues(v)124 // Assertions125 if assert.NoError(t, GetJSON(c)) {126 assert.Equal(t, http.StatusOK, rec.Code)127 }128 }129 req2 := httptest.NewRequest(http.MethodPost, "/", nil)130 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)131 rec2 := httptest.NewRecorder()132 c2 := e.NewContext(req2, rec2)133 c2.SetPath("/rule/:kind")134 c2.SetParamNames("kind")135 c2.SetParamValues("ability")136 // Assertions137 if assert.NoError(t, GetJSON(c2)) {138 assert.Equal(t, http.StatusNotImplemented, rec2.Code)139 }140}141func TestCharacter(t *testing.T) {142 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)143 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)144 e := echo.New()145 example := "{\"key\":\"value\"}"146 requestByte, _ := json.Marshal(example)147 requestReader := bytes.NewReader(requestByte)148 req := httptest.NewRequest(http.MethodPost, "/", requestReader)149 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)150 rec := httptest.NewRecorder()151 c := e.NewContext(req, rec)152 c.SetPath("/roll/character")153 // Assertions154 if assert.NoError(t, Character(c)) {155 assert.Equal(t, http.StatusBadRequest, rec.Code)156 }157 example1 := rule.NewCharacter{}158 requestByte1, _ := json.Marshal(example1)159 requestReader1 := bytes.NewReader(requestByte1)160 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)161 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)162 rec1 := httptest.NewRecorder()163 c1 := e.NewContext(req1, rec1)164 c1.SetPath("/roll/character")165 // Assertions166 if assert.NoError(t, Character(c1)) {167 assert.Equal(t, http.StatusBadRequest, rec1.Code)168 }169 example2 := rule.NewCharacter{170 Level: 1,171 Class: "cleric",172 Race: "human",173 Subrace: "",174 Background: "soldier",175 Ability: map[string]int{176 "strength": 14,177 "dexterity": 10,178 "constitution": 14,179 "intelligence": 10,180 "wisdom": 16,181 "charisma": 14,182 },183 ChosenLanguages: []string{"celestial"},184 ChosenSkills: []string{"religion", "perception"},185 ChosenClassFeatures: []string{"war"},186 }187 requestByte2, _ := json.Marshal(example2)188 requestReader2 := bytes.NewReader(requestByte2)189 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)190 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)191 rec2 := httptest.NewRecorder()192 c2 := e.NewContext(req2, rec2)193 c2.SetPath("/roll/character")194 // Assertions195 if assert.NoError(t, Character(c2)) {196 assert.Equal(t, http.StatusBadRequest, rec2.Code)197 }198 example3 := rule.NewCharacter{199 Level: 1,200 Class: "cleric",201 Race: "human",202 Subrace: "",203 Background: "soldier",204 Ability: map[string]int{205 "strength": 14,206 "dexterity": 10,207 "constitution": 14,208 "intelligence": 10,209 "wisdom": 16,210 "charisma": 14,211 },212 ChosenLanguages: []string{"celestial"},213 ChosenSkills: []string{"religion", "medicine"},214 ChosenClassFeatures: []string{"war"},215 }216 requestByte3, _ := json.Marshal(example3)217 requestReader3 := bytes.NewReader(requestByte3)218 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)219 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)220 rec3 := httptest.NewRecorder()221 c3 := e.NewContext(req3, rec3)222 c3.SetPath("/roll/character")223 // Assertions224 if assert.NoError(t, Character(c3)) {225 assert.Equal(t, http.StatusCreated, rec3.Code)226 }227}228func TestValidateNames(t *testing.T) {229 example1 := rule.NewCharacter{}230 example1.Race = "superhuman"231 _, res1 := validateNames(&example1)232 assert.False(t, res1)233 example2 := rule.NewCharacter{}234 example2.Race = "elf"235 example2.Subrace = "superelf"236 _, res2 := validateNames(&example2)237 assert.False(t, res2)238 example3 := rule.NewCharacter{}239 example3.Race = "elf"240 example3.Subrace = "high-elf"241 example3.Class = "superhero"242 _, res3 := validateNames(&example3)243 assert.False(t, res3)244 example4 := rule.NewCharacter{}245 example4.Race = "elf"246 example4.Subrace = "high-elf"247 example4.Class = "fighter"248 example4.Background = "superhero"249 _, res4 := validateNames(&example4)250 assert.False(t, res4)251 example5 := rule.NewCharacter{}252 example5.Race = "elf"253 example5.Subrace = "high-elf"254 example5.Background = "acolyte"255 example5.Class = "fighter"256 _, res5 := validateNames(&example5)257 assert.False(t, res5)258 example6 := rule.NewCharacter{}259 example6.Race = "elf"260 example6.Subrace = "high-elf"261 example6.Background = "acolyte"262 example6.Class = "fighter"263 example6.Ability = map[string]int{264 "strength": 14,265 "dexterity": 10,266 "constitution": 14,267 "intelligence": 10,268 "wisdom": 16,269 "charisma": 16,270 "super": 14,271 }272 example6.Ability["super"] = 10273 _, res6 := validateNames(&example6)274 assert.False(t, res6)275 example7 := rule.NewCharacter{}276 example7.Race = "elf"277 example7.Subrace = "high-elf"278 example7.Background = "acolyte"279 example7.Class = "fighter"280 example7.Ability = map[string]int{281 "strength": 14,282 "dexterity": 10,283 "constitution": 14,284 "intelligence": 10,285 "wisdom": 16,286 "super": 14,287 }288 _, res7 := validateNames(&example7)289 assert.False(t, res7)290 example8 := rule.NewCharacter{}291 example8.Race = "human"292 example8.Subrace = ""293 example8.Background = "acolyte"294 example8.Class = "fighter"295 example8.Ability = map[string]int{296 "strength": 14,297 "dexterity": 10,298 "constitution": 14,299 "intelligence": 10,300 "wisdom": 16,301 "charisma": 14,302 }303 example8.ChosenLanguages = []string{"elvish", "giant", "gnomish", "draconic", "goblin", "halfling", "orc"}304 _, res8 := validateNames(&example8)305 assert.False(t, res8)306 example9 := rule.NewCharacter{}307 example9.Race = "elf"308 example9.Subrace = "high-elf"309 example9.Background = "acolyte"310 example9.Class = "fighter"311 example9.Ability = map[string]int{312 "strength": 14,313 "dexterity": 10,314 "constitution": 14,315 "intelligence": 10,316 "wisdom": 16,317 "charisma": 14,318 }319 example9.ChosenLanguages = []string{"elvish", "giant", "gnomish"}320 _, res9 := validateNames(&example9)321 assert.False(t, res9)322 example10 := rule.NewCharacter{}323 example10.Race = "elf"324 example10.Subrace = "high-elf"325 example10.Background = "acolyte"326 example10.Class = "fighter"327 example10.Ability = map[string]int{328 "strength": 14,329 "dexterity": 10,330 "constitution": 14,331 "intelligence": 10,332 "wisdom": 16,333 "charisma": 14,334 }335 example10.ChosenLanguages = []string{"giant", "gnomish", "draconic"}336 example10.ChosenSkills = []string{"insight", "intimidation"}337 _, res10 := validateNames(&example10)338 assert.False(t, res10)339 example11 := rule.NewCharacter{}340 example11.Race = "half-elf"341 example11.Subrace = ""342 example11.Background = "acolyte"343 example11.Class = "fighter"344 example11.Ability = map[string]int{345 "strength": 16,346 "dexterity": 10,347 "constitution": 14,348 "intelligence": 12,349 "wisdom": 12,350 "charisma": 12,351 }352 example11.ChosenLanguages = []string{"giant", "gnomish", "draconic"}353 example11.ChosenSkills = []string{"athletics", "intimidation"}354 example11.ChosenAbility = []string{"constitution", "strength", "constitution"}355 _, res11 := validateNames(&example11)356 assert.False(t, res11)357 example12 := rule.NewCharacter{}358 example12.Race = "half-elf"359 example12.Subrace = ""360 example12.Background = "acolyte"361 example12.Class = "fighter"362 example12.Ability = map[string]int{363 "strength": 16,364 "dexterity": 10,365 "constitution": 14,366 "intelligence": 12,367 "wisdom": 12,368 "charisma": 12,369 }370 example12.ChosenLanguages = []string{"giant", "gnomish", "draconic"}371 example12.ChosenSkills = []string{"athletics", "intimidation"}372 example12.ChosenAbility = []string{"constitution", "charisma"}373 _, res12 := validateNames(&example12)374 assert.False(t, res12)375}376func TestCheckFullAttack(t *testing.T) {377 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)378 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)379 e := echo.New()380 example := "{\"key\":\"value\"}"381 requestByte, _ := json.Marshal(example)382 requestReader := bytes.NewReader(requestByte)383 req := httptest.NewRequest(http.MethodPost, "/", requestReader)384 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)385 rec := httptest.NewRecorder()386 c := e.NewContext(req, rec)387 c.SetPath("/roll/player/attack")388 // Assertions389 if assert.NoError(t, CheckFullAttack(c)) {390 assert.Equal(t, http.StatusBadRequest, rec.Code)391 }392 example1 := rule.Attack{}393 requestByte1, _ := json.Marshal(example1)394 requestReader1 := bytes.NewReader(requestByte1)395 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)396 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)397 rec1 := httptest.NewRecorder()398 c1 := e.NewContext(req1, rec1)399 c1.SetPath("/roll/player/attack")400 // Assertions401 if assert.NoError(t, CheckFullAttack(c1)) {402 assert.Equal(t, http.StatusOK, rec1.Code)403 }404}405func TestCheckSpellAttack(t *testing.T) {406 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)407 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)408 e := echo.New()409 example := "{\"key\":\"value\"}"410 requestByte, _ := json.Marshal(example)411 requestReader := bytes.NewReader(requestByte)412 req := httptest.NewRequest(http.MethodPost, "/", requestReader)413 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)414 rec := httptest.NewRecorder()415 c := e.NewContext(req, rec)416 c.SetPath("/roll/player/attack")417 // Assertions418 if assert.NoError(t, CheckSpellAttack(c)) {419 assert.Equal(t, http.StatusBadRequest, rec.Code)420 }421 example1 := rule.SpellcastAbility{}422 example1.Class = "barbarian"423 requestByte1, _ := json.Marshal(example1)424 requestReader1 := bytes.NewReader(requestByte1)425 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)426 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)427 rec1 := httptest.NewRecorder()428 c1 := e.NewContext(req1, rec1)429 c1.SetPath("/roll/player/attack")430 // Assertions431 if assert.NoError(t, CheckSpellAttack(c1)) {432 assert.Equal(t, http.StatusBadRequest, rec1.Code)433 }434 example2 := rule.SpellcastAbility{}435 example2.Class = "sorcerer"436 requestByte2, _ := json.Marshal(example2)437 requestReader2 := bytes.NewReader(requestByte2)438 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)439 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)440 rec2 := httptest.NewRecorder()441 c2 := e.NewContext(req2, rec2)442 c2.SetPath("/roll/player/attack")443 // Assertions444 if assert.NoError(t, CheckSpellAttack(c2)) {445 assert.Equal(t, http.StatusOK, rec2.Code)446 }447}448func TestCheckSkillOrAbility(t *testing.T) {449 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)450 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)451 e := echo.New()452 example := "{\"key\":\"value\"}"453 requestByte, _ := json.Marshal(example)454 requestReader := bytes.NewReader(requestByte)455 req := httptest.NewRequest(http.MethodPost, "/", requestReader)456 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)457 rec := httptest.NewRecorder()458 c := e.NewContext(req, rec)459 c.SetPath("/roll/player/check")460 // Assertions461 if assert.NoError(t, CheckSkillOrAbility(c)) {462 assert.Equal(t, http.StatusBadRequest, rec.Code)463 }464 example1 := rule.SkillOrAbilityCheck{}465 requestByte1, _ := json.Marshal(example1)466 requestReader1 := bytes.NewReader(requestByte1)467 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)468 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)469 rec1 := httptest.NewRecorder()470 c1 := e.NewContext(req1, rec1)471 c1.SetPath("/roll/player/check")472 // Assertions473 if assert.NoError(t, CheckSkillOrAbility(c1)) {474 assert.Equal(t, http.StatusOK, rec1.Code)475 }476}477func TestCheckSavingsAbility(t *testing.T) {478 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)479 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)480 e := echo.New()481 example := "{\"key\":\"value\"}"482 requestByte, _ := json.Marshal(example)483 requestReader := bytes.NewReader(requestByte)484 req := httptest.NewRequest(http.MethodPost, "/", requestReader)485 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)486 rec := httptest.NewRecorder()487 c := e.NewContext(req, rec)488 c.SetPath("/roll/player/savings")489 // Assertions490 if assert.NoError(t, CheckSavingsAbility(c)) {491 assert.Equal(t, http.StatusBadRequest, rec.Code)492 }493 example1 := rule.SavingsCheck{}494 requestByte1, _ := json.Marshal(example1)495 requestReader1 := bytes.NewReader(requestByte1)496 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)497 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)498 rec1 := httptest.NewRecorder()499 c1 := e.NewContext(req1, rec1)500 c1.SetPath("/roll/player/savings")501 // Assertions502 if assert.NoError(t, CheckSavingsAbility(c1)) {503 assert.Equal(t, http.StatusOK, rec1.Code)504 }505}506func TestCalcArmorClass(t *testing.T) {507 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)508 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)509 e := echo.New()510 example := "{\"key\":\"value\"}"511 requestByte, _ := json.Marshal(example)512 requestReader := bytes.NewReader(requestByte)513 req := httptest.NewRequest(http.MethodPost, "/", requestReader)514 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)515 rec := httptest.NewRecorder()516 c := e.NewContext(req, rec)517 c.SetPath("/roll/player/armorclass")518 // Assertions519 if assert.NoError(t, CalcArmorClass(c)) {520 assert.Equal(t, http.StatusBadRequest, rec.Code)521 }522 example1 := rule.ArmorClass{}523 requestByte1, _ := json.Marshal(example1)524 requestReader1 := bytes.NewReader(requestByte1)525 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)526 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)527 rec1 := httptest.NewRecorder()528 c1 := e.NewContext(req1, rec1)529 c1.SetPath("/roll/player/armorclass")530 // Assertions531 if assert.NoError(t, CalcArmorClass(c1)) {532 assert.Equal(t, http.StatusOK, rec1.Code)533 }534}535func TestUseClassFeature(t *testing.T) {536 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)537 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)538 e := echo.New()539 example := "{\"key\":\"value\"}"540 requestByte, _ := json.Marshal(example)541 requestReader := bytes.NewReader(requestByte)542 req := httptest.NewRequest(http.MethodPost, "/", requestReader)543 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)544 rec := httptest.NewRecorder()545 c := e.NewContext(req, rec)546 c.SetPath("/roll/player/classfeature")547 // Assertions548 if assert.NoError(t, UseClassFeature(c)) {549 assert.Equal(t, http.StatusBadRequest, rec.Code)550 }551 example1 := rule.Feature{}552 requestByte1, _ := json.Marshal(example1)553 requestReader1 := bytes.NewReader(requestByte1)554 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)555 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)556 rec1 := httptest.NewRecorder()557 c1 := e.NewContext(req1, rec1)558 c1.SetPath("/roll/player/classfeature")559 // Assertions560 if assert.NoError(t, UseClassFeature(c1)) {561 assert.Equal(t, http.StatusBadRequest, rec1.Code)562 }563 example2 := rule.Feature{}564 example2.Name = "bless"565 requestByte2, _ := json.Marshal(example2)566 requestReader2 := bytes.NewReader(requestByte2)567 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)568 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)569 rec2 := httptest.NewRecorder()570 c2 := e.NewContext(req2, rec2)571 c2.SetPath("/roll/player/classfeature")572 // Assertions573 if assert.NoError(t, UseClassFeature(c2)) {574 assert.Equal(t, http.StatusOK, rec2.Code)575 }576}577func TestUseRaceFeature(t *testing.T) {578 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)579 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)580 e := echo.New()581 example := "{\"key\":\"value\"}"582 requestByte, _ := json.Marshal(example)583 requestReader := bytes.NewReader(requestByte)584 req := httptest.NewRequest(http.MethodPost, "/", requestReader)585 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)586 rec := httptest.NewRecorder()587 c := e.NewContext(req, rec)588 c.SetPath("/roll/player/racefeature")589 // Assertions590 if assert.NoError(t, UseRaceFeature(c)) {591 assert.Equal(t, http.StatusBadRequest, rec.Code)592 }593 example1 := rule.SpecialRaceFeature{}594 requestByte1, _ := json.Marshal(example1)595 requestReader1 := bytes.NewReader(requestByte1)596 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)597 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)598 rec1 := httptest.NewRecorder()599 c1 := e.NewContext(req1, rec1)600 c1.SetPath("/roll/player/racefeature")601 // Assertions602 if assert.NoError(t, UseRaceFeature(c1)) {603 assert.Equal(t, http.StatusBadRequest, rec1.Code)604 }605 example2 := rule.SpecialRaceFeature{}606 example2.Name = "hellish-rebuke"607 example2.Race = "tiefling"608 requestByte2, _ := json.Marshal(example2)609 requestReader2 := bytes.NewReader(requestByte2)610 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)611 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)612 rec2 := httptest.NewRecorder()613 c2 := e.NewContext(req2, rec2)614 c2.SetPath("/roll/player/racefeature")615 // Assertions616 if assert.NoError(t, UseRaceFeature(c2)) {617 assert.Equal(t, http.StatusOK, rec2.Code)618 }619}620func TestCheckPreparedSpellList(t *testing.T) {621 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)622 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)623 e := echo.New()624 example := "{\"key\":\"value\"}"625 requestByte, _ := json.Marshal(example)626 requestReader := bytes.NewReader(requestByte)627 req := httptest.NewRequest(http.MethodPost, "/", requestReader)628 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)629 rec := httptest.NewRecorder()630 c := e.NewContext(req, rec)631 c.SetPath("/roll/player/preparedspells")632 // Assertions633 if assert.NoError(t, CheckPreparedSpellList(c)) {634 assert.Equal(t, http.StatusBadRequest, rec.Code)635 }636 example1 := rule.PreparedSpellsList{}637 example1.Class = "sorcerer"638 requestByte1, _ := json.Marshal(example1)639 requestReader1 := bytes.NewReader(requestByte1)640 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)641 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)642 rec1 := httptest.NewRecorder()643 c1 := e.NewContext(req1, rec1)644 c1.SetPath("/roll/player/preparedspells")645 // Assertions646 if assert.NoError(t, CheckPreparedSpellList(c1)) {647 assert.Equal(t, http.StatusBadRequest, rec1.Code)648 }649 example2 := rule.PreparedSpellsList{}650 example2.Class = "wizard"651 requestByte2, _ := json.Marshal(example2)652 requestReader2 := bytes.NewReader(requestByte2)653 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)654 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)655 rec2 := httptest.NewRecorder()656 c2 := e.NewContext(req2, rec2)657 c2.SetPath("/roll/player/preparedspells")658 // Assertions659 if assert.NoError(t, CheckPreparedSpellList(c2)) {660 assert.Equal(t, http.StatusBadRequest, rec2.Code)661 }662 example3 := rule.PreparedSpellsList{}663 example3.Class = "wizard"664 example3.Level = 1665 example3.PreparedSpells = []string{"chill-touch", "chill-touch", "chill-touch"}666 example3.Ability = map[string]int{667 "strength": 14,668 "dexterity": 10,669 "constitution": 14,670 "intelligence": 14,671 "wisdom": 16,672 "charisma": 14,673 }674 requestByte3, _ := json.Marshal(example3)675 requestReader3 := bytes.NewReader(requestByte3)676 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)677 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)678 rec3 := httptest.NewRecorder()679 c3 := e.NewContext(req3, rec3)680 c3.SetPath("/roll/player/preparedspells")681 // Assertions682 if assert.NoError(t, CheckPreparedSpellList(c3)) {683 assert.Equal(t, http.StatusOK, rec3.Code)684 }685}686func TestCheckKnownSpellList(t *testing.T) {687 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)688 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)689 e := echo.New()690 example := "{\"key\":\"value\"}"691 requestByte, _ := json.Marshal(example)692 requestReader := bytes.NewReader(requestByte)693 req := httptest.NewRequest(http.MethodPost, "/", requestReader)694 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)695 rec := httptest.NewRecorder()696 c := e.NewContext(req, rec)697 c.SetPath("/roll/player/knownspells")698 // Assertions699 if assert.NoError(t, CheckKnownSpellList(c)) {700 assert.Equal(t, http.StatusBadRequest, rec.Code)701 }702 example1 := rule.KnownSpellsList{}703 example1.Class = "wizard"704 requestByte1, _ := json.Marshal(example1)705 requestReader1 := bytes.NewReader(requestByte1)706 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)707 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)708 rec1 := httptest.NewRecorder()709 c1 := e.NewContext(req1, rec1)710 c1.SetPath("/roll/player/knownspells")711 // Assertions712 if assert.NoError(t, CheckKnownSpellList(c1)) {713 assert.Equal(t, http.StatusBadRequest, rec1.Code)714 }715 example2 := rule.KnownSpellsList{}716 example2.Level = 1717 example2.Class = "sorcerer"718 example2.SpellList = []string{"chill-touch", "chill-touch", "chill-touch", "chill-touch", "chill-touch", "chill-touch"}719 requestByte2, _ := json.Marshal(example2)720 requestReader2 := bytes.NewReader(requestByte2)721 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)722 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)723 rec2 := httptest.NewRecorder()724 c2 := e.NewContext(req2, rec2)725 c2.SetPath("/roll/player/knownspells")726 // Assertions727 if assert.NoError(t, CheckKnownSpellList(c2)) {728 assert.Equal(t, http.StatusBadRequest, rec2.Code)729 }730 example3 := rule.KnownSpellsList{}731 example3.Class = "sorcerer"732 example3.Level = 1733 example3.KnownSpells = 2734 example3.SpellList = []string{"chill-touch", "chill-touch"}735 requestByte3, _ := json.Marshal(example3)736 requestReader3 := bytes.NewReader(requestByte3)737 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)738 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)739 rec3 := httptest.NewRecorder()740 c3 := e.NewContext(req3, rec3)741 c3.SetPath("/roll/player/knownspells")742 // Assertions743 if assert.NoError(t, CheckKnownSpellList(c3)) {744 assert.Equal(t, http.StatusOK, rec3.Code)745 }746}747func TestCheckCantripList(t *testing.T) {748 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)749 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)750 e := echo.New()751 example := "{\"key\":\"value\"}"752 requestByte, _ := json.Marshal(example)753 requestReader := bytes.NewReader(requestByte)754 req := httptest.NewRequest(http.MethodPost, "/", requestReader)755 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)756 rec := httptest.NewRecorder()757 c := e.NewContext(req, rec)758 c.SetPath("/roll/player/cantrips")759 // Assertions760 if assert.NoError(t, CheckCantripList(c)) {761 assert.Equal(t, http.StatusBadRequest, rec.Code)762 }763 example1 := rule.KnownCantripList{}764 example1.Class = "paladin"765 requestByte1, _ := json.Marshal(example1)766 requestReader1 := bytes.NewReader(requestByte1)767 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)768 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)769 rec1 := httptest.NewRecorder()770 c1 := e.NewContext(req1, rec1)771 c1.SetPath("/roll/player/cantrips")772 // Assertions773 if assert.NoError(t, CheckCantripList(c1)) {774 assert.Equal(t, http.StatusBadRequest, rec1.Code)775 }776 example2 := rule.KnownCantripList{}777 example2.Class = "fighter"778 example2.ClassFeatures = []string{"archetype-eldritch-knight-spellcasting"}779 requestByte2, _ := json.Marshal(example2)780 requestReader2 := bytes.NewReader(requestByte2)781 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)782 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)783 rec2 := httptest.NewRecorder()784 c2 := e.NewContext(req2, rec2)785 c2.SetPath("/roll/player/cantrips")786 // Assertions787 if assert.NoError(t, CheckCantripList(c2)) {788 assert.Equal(t, http.StatusOK, rec2.Code)789 }790 example3 := rule.KnownCantripList{}791 example3.Class = "rogue"792 example3.ClassFeatures = []string{"archetype-arcane-trickster-spellcasting"}793 requestByte3, _ := json.Marshal(example3)794 requestReader3 := bytes.NewReader(requestByte3)795 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)796 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)797 rec3 := httptest.NewRecorder()798 c3 := e.NewContext(req3, rec3)799 c3.SetPath("/roll/player/cantrips")800 // Assertions801 if assert.NoError(t, CheckCantripList(c3)) {802 assert.Equal(t, http.StatusOK, rec3.Code)803 }804 //acid-splash805 example4 := rule.KnownCantripList{}806 example4.Class = "sorcerer"807 example4.CantripsKnown = 2808 example4.CantripsList = []string{"acid-splash", "chill-touch", "produce-flame"}809 requestByte4, _ := json.Marshal(example4)810 requestReader4 := bytes.NewReader(requestByte4)811 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)812 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)813 rec4 := httptest.NewRecorder()814 c4 := e.NewContext(req4, rec4)815 c4.SetPath("/roll/player/cantrips")816 // Assertions817 if assert.NoError(t, CheckCantripList(c4)) {818 assert.Equal(t, http.StatusBadRequest, rec4.Code)819 }820}821func TestCheckMonsterAttack(t *testing.T) {822 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)823 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)824 e := echo.New()825 example := "{\"key\":\"value\"}"826 requestByte, _ := json.Marshal(example)827 requestReader := bytes.NewReader(requestByte)828 req := httptest.NewRequest(http.MethodPost, "/", requestReader)829 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)830 rec := httptest.NewRecorder()831 c := e.NewContext(req, rec)832 c.SetPath("/roll/npc/attack")833 // Assertions834 if assert.NoError(t, CheckMonsterAttack(c)) {835 assert.Equal(t, http.StatusBadRequest, rec.Code)836 }837 example1 := rule.MonsterRoll{}838 example1.Check = "attack"839 requestByte1, _ := json.Marshal(example1)840 requestReader1 := bytes.NewReader(requestByte1)841 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)842 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)843 rec1 := httptest.NewRecorder()844 c1 := e.NewContext(req1, rec1)845 c1.SetPath("/roll/npc/attack")846 // Assertions847 if assert.NoError(t, CheckMonsterAttack(c1)) {848 assert.Equal(t, http.StatusOK, rec1.Code)849 }850 example2 := rule.MonsterRoll{}851 example2.Check = "attacking"852 requestByte2, _ := json.Marshal(example2)853 requestReader2 := bytes.NewReader(requestByte2)854 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)855 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)856 rec2 := httptest.NewRecorder()857 c2 := e.NewContext(req2, rec2)858 c2.SetPath("/roll/npc/attack")859 // Assertions860 if assert.NoError(t, CheckMonsterAttack(c2)) {861 assert.Equal(t, http.StatusBadRequest, rec2.Code)862 }863}864func TestCheckMonsterSavings(t *testing.T) {865 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)866 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)867 e := echo.New()868 example := "{\"key\":\"value\"}"869 requestByte, _ := json.Marshal(example)870 requestReader := bytes.NewReader(requestByte)871 req := httptest.NewRequest(http.MethodPost, "/", requestReader)872 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)873 rec := httptest.NewRecorder()874 c := e.NewContext(req, rec)875 c.SetPath("/roll/npc/savings")876 // Assertions877 if assert.NoError(t, CheckMonsterSavings(c)) {878 assert.Equal(t, http.StatusBadRequest, rec.Code)879 }880 example1 := rule.MonsterRoll{}881 requestByte1, _ := json.Marshal(example1)882 requestReader1 := bytes.NewReader(requestByte1)883 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)884 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)885 rec1 := httptest.NewRecorder()886 c1 := e.NewContext(req1, rec1)887 c1.SetPath("/roll/npc/savings")888 // Assertions889 if assert.NoError(t, CheckMonsterSavings(c1)) {890 assert.Equal(t, http.StatusOK, rec1.Code)891 }892}893func TestCheckMonsterChecks(t *testing.T) {894 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)895 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)896 e := echo.New()897 example := "{\"key\":\"value\"}"898 requestByte, _ := json.Marshal(example)899 requestReader := bytes.NewReader(requestByte)900 req := httptest.NewRequest(http.MethodPost, "/", requestReader)901 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)902 rec := httptest.NewRecorder()903 c := e.NewContext(req, rec)904 c.SetPath("/roll/npc/checks")905 // Assertions906 if assert.NoError(t, CheckMonsterChecks(c)) {907 assert.Equal(t, http.StatusBadRequest, rec.Code)908 }909 example1 := rule.MonsterRoll{}910 requestByte1, _ := json.Marshal(example1)911 requestReader1 := bytes.NewReader(requestByte1)912 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)913 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)914 rec1 := httptest.NewRecorder()915 c1 := e.NewContext(req1, rec1)916 c1.SetPath("/roll/npc/checks")917 // Assertions918 if assert.NoError(t, CheckMonsterChecks(c1)) {919 assert.Equal(t, http.StatusOK, rec1.Code)920 }921}922func TestCheckMonstersInitiative(t *testing.T) {923 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)924 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)925 e := echo.New()926 example := "{\"key\":\"value\"}"927 requestByte, _ := json.Marshal(example)928 requestReader := bytes.NewReader(requestByte)929 req := httptest.NewRequest(http.MethodPost, "/", requestReader)930 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)931 rec := httptest.NewRecorder()932 c := e.NewContext(req, rec)933 c.SetPath("/roll/npc/initiative")934 // Assertions935 if assert.NoError(t, CheckMonstersInitiative(c)) {936 assert.Equal(t, http.StatusBadRequest, rec.Code)937 }938 example1 := rule.SimpleList{}939 requestByte1, _ := json.Marshal(example1)940 requestReader1 := bytes.NewReader(requestByte1)941 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)942 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)943 rec1 := httptest.NewRecorder()944 c1 := e.NewContext(req1, rec1)945 c1.SetPath("/roll/npc/initiative")946 // Assertions947 if assert.NoError(t, CheckMonstersInitiative(c1)) {948 assert.Equal(t, http.StatusOK, rec1.Code)949 }950}951func TestCheckMonsterTurn(t *testing.T) {952 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)953 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)954 e := echo.New()955 example := "{\"key\":\"value\"}"956 requestByte, _ := json.Marshal(example)957 requestReader := bytes.NewReader(requestByte)958 req := httptest.NewRequest(http.MethodPost, "/", requestReader)959 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)960 rec := httptest.NewRecorder()961 c := e.NewContext(req, rec)962 c.SetPath("/roll/npc/initiative")963 // Assertions964 if assert.NoError(t, CheckMonsterTurn(c)) {965 assert.Equal(t, http.StatusBadRequest, rec.Code)966 }967 example1 := rule.MonsterTurn{}968 requestByte1, _ := json.Marshal(example1)969 requestReader1 := bytes.NewReader(requestByte1)970 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)971 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)972 rec1 := httptest.NewRecorder()973 c1 := e.NewContext(req1, rec1)974 c1.SetPath("/roll/npc/turnundead")975 // Assertions976 if assert.NoError(t, CheckMonsterTurn(c1)) {977 assert.Equal(t, http.StatusBadRequest, rec1.Code)978 }979 example2 := rule.MonsterTurn{}980 example2.ClassFeatures = []string{"sacred-oath-of-devotion-channel-divinity"}981 requestByte2, _ := json.Marshal(example2)982 requestReader2 := bytes.NewReader(requestByte2)983 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)984 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)985 rec2 := httptest.NewRecorder()986 c2 := e.NewContext(req2, rec2)987 c2.SetPath("/roll/npc/turnundead")988 // Assertions989 if assert.NoError(t, CheckMonsterTurn(c2)) {990 assert.Equal(t, http.StatusOK, rec2.Code)991 }992}993func TestUsePotionPlayer(t *testing.T) {994 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)995 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)996 e := echo.New()997 example := "{\"key\":\"value\"}"998 requestByte, _ := json.Marshal(example)999 requestReader := bytes.NewReader(requestByte)1000 req := httptest.NewRequest(http.MethodPost, "/", requestReader)1001 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)1002 rec := httptest.NewRecorder()1003 c := e.NewContext(req, rec)1004 c.SetPath("/roll/player/potion")1005 // Assertions1006 if assert.NoError(t, UsePotionPlayer(c)) {1007 assert.Equal(t, http.StatusBadRequest, rec.Code)1008 }1009 example1 := rule.Potion{}1010 requestByte1, _ := json.Marshal(example1)1011 requestReader1 := bytes.NewReader(requestByte1)1012 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)1013 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)1014 rec1 := httptest.NewRecorder()1015 c1 := e.NewContext(req1, rec1)1016 c1.SetPath("/roll/player/potion")1017 // Assertions1018 if assert.NoError(t, UsePotionPlayer(c1)) {1019 assert.Equal(t, http.StatusBadRequest, rec1.Code)1020 }1021 example2 := rule.Potion{}1022 example2.Name = "potion-of-climbing"1023 requestByte2, _ := json.Marshal(example2)1024 requestReader2 := bytes.NewReader(requestByte2)1025 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)1026 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)1027 rec2 := httptest.NewRecorder()1028 c2 := e.NewContext(req2, rec2)1029 c2.SetPath("/roll/player/potion")1030 // Assertions1031 if assert.NoError(t, UsePotionPlayer(c2)) {1032 assert.Equal(t, http.StatusOK, rec2.Code)1033 }1034}...
players_controller_test.go
Source:players_controller_test.go
...16)17func TestGetAllPlayers(t *testing.T) {18 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)19 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)20 e := echo.New()21 req := httptest.NewRequest(http.MethodGet, "/", nil)22 rec := httptest.NewRecorder()23 c := e.NewContext(req, rec)24 c.SetPath("/player")25 // Assertions26 if assert.NoError(t, GetAllPlayers(c)) {27 assert.Equal(t, http.StatusOK, rec.Code)28 }29}30func TestGetOnePlayer(t *testing.T) {31 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)32 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)33 e := echo.New()34 req := httptest.NewRequest(http.MethodGet, "/", nil)35 rec := httptest.NewRecorder()36 c := e.NewContext(req, rec)37 c.SetPath("/player/:id")38 c.SetParamNames("id")39 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")40 // Assertions41 if assert.NoError(t, GetOnePlayer(c)) {42 assert.Equal(t, http.StatusOK, rec.Code)43 }44 req1 := httptest.NewRequest(http.MethodGet, "/", nil)45 rec1 := httptest.NewRecorder()46 c1 := e.NewContext(req1, rec1)47 c1.SetPath("/player/:id")48 c1.SetParamNames("id")49 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")50 if assert.NoError(t, GetOnePlayer(c1)) {51 assert.Equal(t, http.StatusUnprocessableEntity, rec1.Code)52 }53 req2 := httptest.NewRequest(http.MethodGet, "/", nil)54 rec2 := httptest.NewRecorder()55 c2 := e.NewContext(req2, rec2)56 c2.SetPath("/player/:id")57 c2.SetParamNames("id")58 c2.SetParamValues("BLA")59 if assert.NoError(t, GetOnePlayer(c2)) {60 assert.Equal(t, http.StatusBadRequest, rec2.Code)61 }62}63func TestPostPlayer(t *testing.T) {64 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)65 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)66 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)67 e := echo.New()68 example := "{\"key\":\"value\"}"69 requestByte, _ := json.Marshal(example)70 requestReader := bytes.NewReader(requestByte)71 req := httptest.NewRequest(http.MethodPost, "/", requestReader)72 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)73 rec := httptest.NewRecorder()74 c := e.NewContext(req, rec)75 c.SetPath("/player")76 // Assertions77 if assert.NoError(t, PostPlayer(c)) {78 assert.Equal(t, http.StatusBadRequest, rec.Code)79 }80 // example1 := player.Players{}81 // example1.AdventureID = "BLA"82 // requestByte1, _ := json.Marshal(example1)83 // requestReader1 := bytes.NewReader(requestByte1)84 // req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)85 // req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)86 // rec1 := httptest.NewRecorder()87 // c1 := e.NewContext(req1, rec1)88 // c1.SetPath("/player")89 // // Assertions90 // if assert.NoError(t, PostPlayer(c1)) {91 // assert.Equal(t, http.StatusBadRequest, rec1.Code)92 // }93 // example2 := player.Players{}94 // requestByte2, _ := json.Marshal(example2)95 // requestReader2 := bytes.NewReader(requestByte2)96 // req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)97 // req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)98 // rec2 := httptest.NewRecorder()99 // c2 := e.NewContext(req2, rec2)100 // c2.SetPath("/player")101 // // Assertions102 // if assert.NoError(t, PostPlayer(c2)) {103 // assert.Equal(t, http.StatusBadRequest, rec2.Code)104 // }105 example3 := player.Players{}106 requestByte3, _ := json.Marshal(example3)107 requestReader3 := bytes.NewReader(requestByte3)108 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)109 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)110 rec3 := httptest.NewRecorder()111 c3 := e.NewContext(req3, rec3)112 c3.SetPath("/player")113 // Assertions114 if assert.NoError(t, PostPlayer(c3)) {115 assert.Equal(t, http.StatusOK, rec3.Code)116 }117 // example4 := player.Players{}118 // requestByte4, _ := json.Marshal(example4)119 // requestReader4 := bytes.NewReader(requestByte4)120 // req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)121 // req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)122 // rec4 := httptest.NewRecorder()123 // c4 := e.NewContext(req4, rec4)124 // c4.SetPath("/player")125 // // Assertions126 // if assert.NoError(t, PostPlayer(c4)) {127 // assert.Equal(t, http.StatusBadRequest, rec4.Code)128 // }129}130func TestUpdateOnePlayer(t *testing.T) {131 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)132 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)133 e := echo.New()134 example := "{\"key\":\"value\"}"135 requestByte, _ := json.Marshal(example)136 requestReader := bytes.NewReader(requestByte)137 req := httptest.NewRequest(http.MethodPut, "/", requestReader)138 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)139 rec := httptest.NewRecorder()140 c := e.NewContext(req, rec)141 c.SetPath("/player")142 // Assertions143 if assert.NoError(t, UpdateOnePlayer(c)) {144 assert.Equal(t, http.StatusBadRequest, rec.Code)145 }146 // example1 := player.Players{}147 // requestByte1, _ := json.Marshal(example1)148 // requestReader1 := bytes.NewReader(requestByte1)149 // req1 := httptest.NewRequest(http.MethodPut, "/", requestReader1)150 // req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)151 // rec1 := httptest.NewRecorder()152 // c1 := e.NewContext(req1, rec1)153 // c1.SetPath("/player")154 // // Assertions155 // if assert.NoError(t, UpdateOnePlayer(c1)) {156 // assert.Equal(t, http.StatusBadRequest, rec1.Code)157 // }158 // example2 := player.Players{}159 // requestByte2, _ := json.Marshal(example2)160 // requestReader2 := bytes.NewReader(requestByte2)161 // req2 := httptest.NewRequest(http.MethodPut, "/", requestReader2)162 // req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)163 // rec2 := httptest.NewRecorder()164 // c2 := e.NewContext(req2, rec2)165 // c2.SetPath("/player")166 // // Assertions167 // if assert.NoError(t, UpdateOnePlayer(c2)) {168 // assert.Equal(t, http.StatusBadRequest, rec2.Code)169 // }170 example3 := player.Players{}171 requestByte3, _ := json.Marshal(example3)172 requestReader3 := bytes.NewReader(requestByte3)173 req3 := httptest.NewRequest(http.MethodPut, "/", requestReader3)174 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)175 rec3 := httptest.NewRecorder()176 c3 := e.NewContext(req3, rec3)177 c3.SetPath("/player")178 // Assertions179 if assert.NoError(t, UpdateOnePlayer(c3)) {180 assert.Equal(t, http.StatusOK, rec3.Code)181 }182 config.Values.RuleBuiltin = false183 example4 := player.Players{}184 requestByte4, _ := json.Marshal(example4)185 requestReader4 := bytes.NewReader(requestByte4)186 req4 := httptest.NewRequest(http.MethodPut, "/", requestReader4)187 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)188 rec4 := httptest.NewRecorder()189 c4 := e.NewContext(req4, rec4)190 c4.SetPath("/player")191 // Assertions192 if assert.NoError(t, UpdateOnePlayer(c4)) {193 assert.Equal(t, http.StatusOK, rec4.Code)194 }195}196func TestDeletePlayer(t *testing.T) {197 e := echo.New()198 req := httptest.NewRequest(http.MethodDelete, "/", nil)199 rec := httptest.NewRecorder()200 c := e.NewContext(req, rec)201 c.SetPath("/player/:id")202 c.SetParamNames("id")203 c.SetParamValues("5e70e4c5d2f3f777c16b29f7")204 // Assertions205 if assert.NoError(t, DeletePlayer(c)) {206 assert.Equal(t, http.StatusOK, rec.Code)207 }208 req1 := httptest.NewRequest(http.MethodDelete, "/", nil)209 rec1 := httptest.NewRecorder()210 c1 := e.NewContext(req1, rec1)211 c1.SetPath("/player/:id")212 c1.SetParamNames("id")213 c1.SetParamValues("BLA")214 // Assertions215 if assert.NoError(t, DeletePlayer(c1)) {216 assert.Equal(t, http.StatusBadRequest, rec1.Code)217 }218 //219 req2 := httptest.NewRequest(http.MethodDelete, "/", nil)220 rec2 := httptest.NewRecorder()221 c2 := e.NewContext(req2, rec2)222 c2.SetPath("/player/:id")223 c2.SetParamNames("id")224 c2.SetParamValues("5e70e4c5d2f3f777c16b29f8")225 // Assertions226 if assert.NoError(t, DeletePlayer(c2)) {227 assert.Equal(t, http.StatusBadRequest, rec2.Code)228 }229}230func TestAddCampaignToPlayer(t *testing.T) {231 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)232 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)233 e := echo.New()234 example := player.AddCampaign{}235 requestByte, _ := json.Marshal(example)236 requestReader := bytes.NewReader(requestByte)237 req := httptest.NewRequest(http.MethodPost, "/", requestReader)238 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)239 rec := httptest.NewRecorder()240 c := e.NewContext(req, rec)241 c.SetPath("/player/:id/campaign")242 c.SetParamNames("id")243 c.SetParamValues("BLA")244 // Assertions245 if assert.NoError(t, AddCampaignToPlayer(c)) {246 assert.Equal(t, http.StatusBadRequest, rec.Code)247 }248 example1 := player.AddCampaign{}249 requestByte1, _ := json.Marshal(example1)250 requestReader1 := bytes.NewReader(requestByte1)251 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)252 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)253 rec1 := httptest.NewRecorder()254 c1 := e.NewContext(req1, rec1)255 c1.SetPath("/player/:id/campaign")256 c1.SetParamNames("id")257 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")258 // Assertions259 if assert.NoError(t, AddCampaignToPlayer(c1)) {260 assert.Equal(t, http.StatusBadRequest, rec1.Code)261 }262 example2 := "{\"key\":\"value\"}"263 requestByte2, _ := json.Marshal(example2)264 requestReader2 := bytes.NewReader(requestByte2)265 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)266 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)267 rec2 := httptest.NewRecorder()268 c2 := e.NewContext(req2, rec2)269 c2.SetPath("/player/:id/campaign")270 c2.SetParamNames("id")271 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")272 // Assertions273 if assert.NoError(t, AddCampaignToPlayer(c2)) {274 assert.Equal(t, http.StatusBadRequest, rec2.Code)275 }276 example3 := player.AddCampaign{}277 requestByte3, _ := json.Marshal(example3)278 requestReader3 := bytes.NewReader(requestByte3)279 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)280 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)281 rec3 := httptest.NewRecorder()282 c3 := e.NewContext(req3, rec3)283 c3.SetPath("/player/:id/campaign")284 c3.SetParamNames("id")285 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6")286 // Assertions287 if assert.NoError(t, AddCampaignToPlayer(c3)) {288 assert.Equal(t, http.StatusOK, rec3.Code)289 }290}291func TestAddOrRemoveHP(t *testing.T) {292 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)293 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)294 e := echo.New()295 req := httptest.NewRequest(http.MethodPut, "/", nil)296 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)297 rec := httptest.NewRecorder()298 c := e.NewContext(req, rec)299 c.SetPath("/player/:id/hp/:action/:value")300 c.SetParamNames("id", "action", "value")301 c.SetParamValues("BLA", "add", "10")302 // Assertions303 if assert.NoError(t, AddOrRemoveHP(c)) {304 assert.Equal(t, http.StatusBadRequest, rec.Code)305 }306 req1 := httptest.NewRequest(http.MethodPut, "/", nil)307 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)308 rec1 := httptest.NewRecorder()309 c1 := e.NewContext(req1, rec1)310 c1.SetPath("/player/:id/hp/:action/:value")311 c1.SetParamNames("id", "action", "value")312 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "add", "10")313 // Assertions314 if assert.NoError(t, AddOrRemoveHP(c1)) {315 assert.Equal(t, http.StatusBadRequest, rec1.Code)316 }317 req2 := httptest.NewRequest(http.MethodPut, "/", nil)318 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)319 rec2 := httptest.NewRecorder()320 c2 := e.NewContext(req2, rec2)321 c2.SetPath("/player/:id/hp/:action/:value")322 c2.SetParamNames("id", "action", "value")323 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "delete", "10")324 // Assertions325 if assert.NoError(t, AddOrRemoveHP(c2)) {326 assert.Equal(t, http.StatusBadRequest, rec2.Code)327 }328 req3 := httptest.NewRequest(http.MethodPut, "/", nil)329 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)330 rec3 := httptest.NewRecorder()331 c3 := e.NewContext(req3, rec3)332 c3.SetPath("/player/:id/hp/:action/:value")333 c3.SetParamNames("id", "action", "value")334 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add", "third")335 // Assertions336 if assert.NoError(t, AddOrRemoveHP(c3)) {337 assert.Equal(t, http.StatusBadRequest, rec3.Code)338 }339 req4 := httptest.NewRequest(http.MethodPut, "/", nil)340 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)341 rec4 := httptest.NewRecorder()342 c4 := e.NewContext(req4, rec4)343 c4.SetPath("/player/:id/hp/:action/:value")344 c4.SetParamNames("id", "action", "value")345 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add", "10")346 // Assertions347 if assert.NoError(t, AddOrRemoveHP(c4)) {348 assert.Equal(t, http.StatusOK, rec4.Code)349 }350}351func TestAddPlayerXP(t *testing.T) {352 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)353 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)354 e := echo.New()355 req := httptest.NewRequest(http.MethodPut, "/", nil)356 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)357 rec := httptest.NewRecorder()358 c := e.NewContext(req, rec)359 c.SetPath("/player/:id/xp/:value")360 c.SetParamNames("id", "value")361 c.SetParamValues("BLA", "10")362 // Assertions363 if assert.NoError(t, AddPlayerXP(c)) {364 assert.Equal(t, http.StatusBadRequest, rec.Code)365 }366 req1 := httptest.NewRequest(http.MethodPut, "/", nil)367 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)368 rec1 := httptest.NewRecorder()369 c1 := e.NewContext(req1, rec1)370 c1.SetPath("/player/:id/xp/:value")371 c1.SetParamNames("id", "value")372 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "10")373 // Assertions374 if assert.NoError(t, AddPlayerXP(c1)) {375 assert.Equal(t, http.StatusBadRequest, rec1.Code)376 }377 req2 := httptest.NewRequest(http.MethodPut, "/", nil)378 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)379 rec2 := httptest.NewRecorder()380 c2 := e.NewContext(req2, rec2)381 c2.SetPath("/player/:id/xp/:value")382 c2.SetParamNames("id", "value")383 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "third")384 // Assertions385 if assert.NoError(t, AddPlayerXP(c2)) {386 assert.Equal(t, http.StatusBadRequest, rec2.Code)387 }388 req3 := httptest.NewRequest(http.MethodPut, "/", nil)389 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)390 rec3 := httptest.NewRecorder()391 c3 := e.NewContext(req3, rec3)392 c3.SetPath("/player/:id/xp/:value")393 c3.SetParamNames("id", "value")394 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "100")395 // Assertions396 if assert.NoError(t, AddPlayerXP(c3)) {397 assert.Equal(t, http.StatusOK, rec3.Code)398 }399 // req4 := httptest.NewRequest(http.MethodPut, "/", nil)400 // req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)401 // rec4 := httptest.NewRecorder()402 // c4 := e.NewContext(req4, rec4)403 // c4.SetPath("/player/:id/xp/:value")404 // c4.SetParamNames("id", "value")405 // c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "10")406 // // Assertions407 // if assert.NoError(t, AddPlayerXP(c4)) {408 // assert.Equal(t, http.StatusOK, rec4.Code)409 // }410}411func TestUseSpellByLevel(t *testing.T) {412 //413 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)414 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)415 e := echo.New()416 req := httptest.NewRequest(http.MethodPut, "/", nil)417 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)418 rec := httptest.NewRecorder()419 c := e.NewContext(req, rec)420 c.SetPath("/player/:id/spell/:level/:value")421 c.SetParamNames("id", "level", "value")422 c.SetParamValues("BLA", "1", "1")423 // Assertions424 if assert.NoError(t, UseSpellByLevel(c)) {425 assert.Equal(t, http.StatusBadRequest, rec.Code)426 }427 req1 := httptest.NewRequest(http.MethodPut, "/", nil)428 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)429 rec1 := httptest.NewRecorder()430 c1 := e.NewContext(req1, rec1)431 c1.SetPath("/player/:id/spell/:level/:value")432 c1.SetParamNames("id", "level", "value")433 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "1", "1")434 // Assertions435 if assert.NoError(t, UseSpellByLevel(c1)) {436 assert.Equal(t, http.StatusBadRequest, rec1.Code)437 }438 req2 := httptest.NewRequest(http.MethodPut, "/", nil)439 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)440 rec2 := httptest.NewRecorder()441 c2 := e.NewContext(req2, rec2)442 c2.SetPath("/player/:id/spell/:level/:value")443 c2.SetParamNames("id", "level", "value")444 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "10", "1")445 // Assertions446 if assert.NoError(t, UseSpellByLevel(c2)) {447 assert.Equal(t, http.StatusBadRequest, rec2.Code)448 }449 req3 := httptest.NewRequest(http.MethodPut, "/", nil)450 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)451 rec3 := httptest.NewRecorder()452 c3 := e.NewContext(req3, rec3)453 c3.SetPath("/player/:id/spell/:level/:value")454 c3.SetParamNames("id", "level", "value")455 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "1", "one")456 // Assertions457 if assert.NoError(t, UseSpellByLevel(c3)) {458 assert.Equal(t, http.StatusBadRequest, rec3.Code)459 }460 req4 := httptest.NewRequest(http.MethodPut, "/", nil)461 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)462 rec4 := httptest.NewRecorder()463 c4 := e.NewContext(req4, rec4)464 c4.SetPath("/player/:id/spell/:level/:value")465 c4.SetParamNames("id", "level", "value")466 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6", "1", "1")467 // Assertions468 if assert.NoError(t, UseSpellByLevel(c4)) {469 assert.Equal(t, http.StatusOK, rec4.Code)470 }471}472func TestFullRestPlayer(t *testing.T) {473 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)474 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)475 e := echo.New()476 req := httptest.NewRequest(http.MethodPut, "/", nil)477 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)478 rec := httptest.NewRecorder()479 c := e.NewContext(req, rec)480 c.SetPath("/player/:id/fullrest")481 c.SetParamNames("id")482 c.SetParamValues("BLA")483 // Assertions484 if assert.NoError(t, FullRestPlayer(c)) {485 assert.Equal(t, http.StatusBadRequest, rec.Code)486 }487 req1 := httptest.NewRequest(http.MethodPut, "/", nil)488 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)489 rec1 := httptest.NewRecorder()490 c1 := e.NewContext(req1, rec1)491 c1.SetPath("/player/:id/fullrest")492 c1.SetParamNames("id")493 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")494 // Assertions495 if assert.NoError(t, FullRestPlayer(c1)) {496 assert.Equal(t, http.StatusBadRequest, rec1.Code)497 }498 req2 := httptest.NewRequest(http.MethodPut, "/", nil)499 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)500 rec2 := httptest.NewRecorder()501 c2 := e.NewContext(req2, rec2)502 c2.SetPath("/player/:id/fullrest")503 c2.SetParamNames("id")504 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")505 // Assertions506 if assert.NoError(t, FullRestPlayer(c2)) {507 assert.Equal(t, http.StatusOK, rec2.Code)508 }509 // req3 := httptest.NewRequest(http.MethodPut, "/", nil)510 // req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)511 // rec3 := httptest.NewRecorder()512 // c3 := e.NewContext(req3, rec3)513 // c3.SetPath("/player/:id/fullrest")514 // c3.SetParamNames("id", "value")515 // c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "100")516 // // Assertions517 // if assert.NoError(t, FullRestPlayer(c3)) {518 // assert.Equal(t, http.StatusOK, rec3.Code)519 // }520}521func TestChangeCondition(t *testing.T) {522 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)523 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)524 e := echo.New()525 // player.Condition526 example := player.Condition{}527 requestByte, _ := json.Marshal(example)528 requestReader := bytes.NewReader(requestByte)529 req := httptest.NewRequest(http.MethodPost, "/", requestReader)530 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)531 rec := httptest.NewRecorder()532 c := e.NewContext(req, rec)533 c.SetPath("/player/:id/condition")534 c.SetParamNames("id")535 c.SetParamValues("BLA")536 // Assertions537 if assert.NoError(t, ChangeCondition(c)) {538 assert.Equal(t, http.StatusBadRequest, rec.Code)539 }540 example1 := player.Condition{}541 requestByte1, _ := json.Marshal(example1)542 requestReader1 := bytes.NewReader(requestByte1)543 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)544 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)545 rec1 := httptest.NewRecorder()546 c1 := e.NewContext(req1, rec1)547 c1.SetPath("/player/:id/condition")548 c1.SetParamNames("id")549 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")550 // Assertions551 if assert.NoError(t, ChangeCondition(c1)) {552 assert.Equal(t, http.StatusBadRequest, rec1.Code)553 }554 example2 := "{\"key\":\"value\"}"555 requestByte2, _ := json.Marshal(example2)556 requestReader2 := bytes.NewReader(requestByte2)557 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)558 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)559 rec2 := httptest.NewRecorder()560 c2 := e.NewContext(req2, rec2)561 c2.SetPath("/player/:id/condition")562 c2.SetParamNames("id")563 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")564 // Assertions565 if assert.NoError(t, ChangeCondition(c2)) {566 assert.Equal(t, http.StatusBadRequest, rec2.Code)567 }568 example3 := player.Condition{}569 requestByte3, _ := json.Marshal(example3)570 requestReader3 := bytes.NewReader(requestByte3)571 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)572 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)573 rec3 := httptest.NewRecorder()574 c3 := e.NewContext(req3, rec3)575 c3.SetPath("/player/:id/condition")576 c3.SetParamNames("id")577 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6")578 // Assertions579 if assert.NoError(t, ChangeCondition(c3)) {580 assert.Equal(t, http.StatusOK, rec3.Code)581 }582}583func TestAddTreasure(t *testing.T) {584 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)585 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)586 e := echo.New()587 example := player.Treasure{}588 requestByte, _ := json.Marshal(example)589 requestReader := bytes.NewReader(requestByte)590 req := httptest.NewRequest(http.MethodPost, "/", requestReader)591 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)592 rec := httptest.NewRecorder()593 c := e.NewContext(req, rec)594 c.SetPath("/player/:id/treasure")595 c.SetParamNames("id")596 c.SetParamValues("BLA")597 // Assertions598 if assert.NoError(t, AddTreasure(c)) {599 assert.Equal(t, http.StatusBadRequest, rec.Code)600 }601 example1 := player.Treasure{}602 requestByte1, _ := json.Marshal(example1)603 requestReader1 := bytes.NewReader(requestByte1)604 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)605 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)606 rec1 := httptest.NewRecorder()607 c1 := e.NewContext(req1, rec1)608 c1.SetPath("/player/:id/treasure")609 c1.SetParamNames("id")610 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")611 // Assertions612 if assert.NoError(t, AddTreasure(c1)) {613 assert.Equal(t, http.StatusBadRequest, rec1.Code)614 }615 example2 := "{\"key\":\"value\"}"616 requestByte2, _ := json.Marshal(example2)617 requestReader2 := bytes.NewReader(requestByte2)618 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)619 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)620 rec2 := httptest.NewRecorder()621 c2 := e.NewContext(req2, rec2)622 c2.SetPath("/player/:id/treasure")623 c2.SetParamNames("id")624 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")625 // Assertions626 if assert.NoError(t, AddTreasure(c2)) {627 assert.Equal(t, http.StatusBadRequest, rec2.Code)628 }629 example3 := player.Treasure{}630 requestByte3, _ := json.Marshal(example3)631 requestReader3 := bytes.NewReader(requestByte3)632 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)633 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)634 rec3 := httptest.NewRecorder()635 c3 := e.NewContext(req3, rec3)636 c3.SetPath("/player/:id/treasure")637 c3.SetParamNames("id")638 c3.SetParamValues("5e70e4c5d2f3f777c16b29f9")639 // Assertions640 if assert.NoError(t, AddTreasure(c3)) {641 assert.Equal(t, http.StatusBadRequest, rec3.Code)642 }643 example4 := player.Treasure{}644 requestByte4, _ := json.Marshal(example4)645 requestReader4 := bytes.NewReader(requestByte4)646 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)647 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)648 rec4 := httptest.NewRecorder()649 c4 := e.NewContext(req4, rec4)650 c4.SetPath("/player/:id/treasure")651 c4.SetParamNames("id")652 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6")653 // Assertions654 if assert.NoError(t, AddTreasure(c4)) {655 assert.Equal(t, http.StatusOK, rec4.Code)656 }657}658func TestAddOrRemoveOtherItems(t *testing.T) {659 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)660 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)661 e := echo.New()662 example := rule.SimpleList{}663 requestByte, _ := json.Marshal(example)664 requestReader := bytes.NewReader(requestByte)665 req := httptest.NewRequest(http.MethodPost, "/", requestReader)666 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)667 rec := httptest.NewRecorder()668 c := e.NewContext(req, rec)669 c.SetPath("/player/:id/items/:action")670 c.SetParamNames("id", "action")671 c.SetParamValues("BLA", "add")672 // Assertions673 if assert.NoError(t, AddOrRemoveOtherItems(c)) {674 assert.Equal(t, http.StatusBadRequest, rec.Code)675 }676 example1 := rule.SimpleList{}677 requestByte1, _ := json.Marshal(example1)678 requestReader1 := bytes.NewReader(requestByte1)679 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)680 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)681 rec1 := httptest.NewRecorder()682 c1 := e.NewContext(req1, rec1)683 c1.SetPath("/player/:id/items/:action")684 c1.SetParamNames("id", "action")685 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "add")686 // Assertions687 if assert.NoError(t, AddOrRemoveOtherItems(c1)) {688 assert.Equal(t, http.StatusBadRequest, rec1.Code)689 }690 example2 := "{\"key\":\"value\"}"691 requestByte2, _ := json.Marshal(example2)692 requestReader2 := bytes.NewReader(requestByte2)693 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)694 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)695 rec2 := httptest.NewRecorder()696 c2 := e.NewContext(req2, rec2)697 c2.SetPath("/player/:id/items/:action")698 c2.SetParamNames("id", "action")699 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")700 // Assertions701 if assert.NoError(t, AddOrRemoveOtherItems(c2)) {702 assert.Equal(t, http.StatusBadRequest, rec2.Code)703 }704 example3 := rule.SimpleList{}705 requestByte3, _ := json.Marshal(example3)706 requestReader3 := bytes.NewReader(requestByte3)707 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)708 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)709 rec3 := httptest.NewRecorder()710 c3 := e.NewContext(req3, rec3)711 c3.SetPath("/player/:id/items/:action")712 c3.SetParamNames("id", "action")713 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "delete")714 // Assertions715 if assert.NoError(t, AddOrRemoveOtherItems(c3)) {716 assert.Equal(t, http.StatusBadRequest, rec3.Code)717 }718 example4 := rule.SimpleList{}719 requestByte4, _ := json.Marshal(example4)720 requestReader4 := bytes.NewReader(requestByte4)721 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)722 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)723 rec4 := httptest.NewRecorder()724 c4 := e.NewContext(req4, rec4)725 c4.SetPath("/player/:id/items/:action")726 c4.SetParamNames("id", "action")727 c4.SetParamValues("5e70e4c5d2f3f777c16b29f9", "add")728 // Assertions729 if assert.NoError(t, AddOrRemoveOtherItems(c4)) {730 assert.Equal(t, http.StatusBadRequest, rec4.Code)731 }732 example5 := rule.SimpleList{}733 requestByte5, _ := json.Marshal(example5)734 requestReader5 := bytes.NewReader(requestByte5)735 req5 := httptest.NewRequest(http.MethodPost, "/", requestReader5)736 req5.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)737 rec5 := httptest.NewRecorder()738 c5 := e.NewContext(req5, rec5)739 c5.SetPath("/player/:id/items/:action")740 c5.SetParamNames("id", "action")741 c5.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")742 // Assertions743 if assert.NoError(t, AddOrRemoveOtherItems(c5)) {744 assert.Equal(t, http.StatusOK, rec5.Code)745 }746}747func TestAddArmorWeaponPlayerByID(t *testing.T) {748 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)749 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)750 e := echo.New()751 example := player.Armory{}752 requestByte, _ := json.Marshal(example)753 requestReader := bytes.NewReader(requestByte)754 req := httptest.NewRequest(http.MethodPost, "/", requestReader)755 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)756 rec := httptest.NewRecorder()757 c := e.NewContext(req, rec)758 c.SetPath("/player/:id/armory")759 c.SetParamNames("id")760 c.SetParamValues("BLA")761 // Assertions762 if assert.NoError(t, AddArmorWeaponPlayerByID(c)) {763 assert.Equal(t, http.StatusBadRequest, rec.Code)764 }765 example1 := player.Armory{}766 requestByte1, _ := json.Marshal(example1)767 requestReader1 := bytes.NewReader(requestByte1)768 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)769 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)770 rec1 := httptest.NewRecorder()771 c1 := e.NewContext(req1, rec1)772 c1.SetPath("/player/:id/armory")773 c1.SetParamNames("id")774 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8")775 // Assertions776 if assert.NoError(t, AddArmorWeaponPlayerByID(c1)) {777 assert.Equal(t, http.StatusBadRequest, rec1.Code)778 }779 example2 := "{\"key\":\"value\"}"780 requestByte2, _ := json.Marshal(example2)781 requestReader2 := bytes.NewReader(requestByte2)782 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)783 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)784 rec2 := httptest.NewRecorder()785 c2 := e.NewContext(req2, rec2)786 c2.SetPath("/player/:id/armory")787 c2.SetParamNames("id")788 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6")789 // Assertions790 if assert.NoError(t, AddArmorWeaponPlayerByID(c2)) {791 assert.Equal(t, http.StatusBadRequest, rec2.Code)792 }793 example3 := player.Armory{}794 requestByte3, _ := json.Marshal(example3)795 requestReader3 := bytes.NewReader(requestByte3)796 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)797 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)798 rec3 := httptest.NewRecorder()799 c3 := e.NewContext(req3, rec3)800 c3.SetPath("/player/:id/armory")801 c3.SetParamNames("id")802 c3.SetParamValues("5e70e4c5d2f3f777c16b29f9")803 // Assertions804 if assert.NoError(t, AddArmorWeaponPlayerByID(c3)) {805 assert.Equal(t, http.StatusBadRequest, rec3.Code)806 }807 example4 := player.Armory{}808 requestByte4, _ := json.Marshal(example4)809 requestReader4 := bytes.NewReader(requestByte4)810 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)811 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)812 rec4 := httptest.NewRecorder()813 c4 := e.NewContext(req4, rec4)814 c4.SetPath("/player/:id/armory")815 c4.SetParamNames("id")816 c4.SetParamValues("5e70e4c5d2f3f777c16b29f6")817 // Assertions818 if assert.NoError(t, AddArmorWeaponPlayerByID(c4)) {819 assert.Equal(t, http.StatusOK, rec4.Code)820 }821}822func TestAddOrRemoveMagicItems(t *testing.T) {823 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)824 appcontext.Current.Add(appcontext.MongoRepository, test.InitMongoMock)825 e := echo.New()826 example := rule.SimpleList{}827 requestByte, _ := json.Marshal(example)828 requestReader := bytes.NewReader(requestByte)829 req := httptest.NewRequest(http.MethodPost, "/", requestReader)830 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)831 rec := httptest.NewRecorder()832 c := e.NewContext(req, rec)833 c.SetPath("/player/:id/magicitems/:action")834 c.SetParamNames("id", "action")835 c.SetParamValues("BLA", "add")836 // Assertions837 if assert.NoError(t, AddOrRemoveMagicItems(c)) {838 assert.Equal(t, http.StatusBadRequest, rec.Code)839 }840 example1 := rule.SimpleList{}841 requestByte1, _ := json.Marshal(example1)842 requestReader1 := bytes.NewReader(requestByte1)843 req1 := httptest.NewRequest(http.MethodPost, "/", requestReader1)844 req1.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)845 rec1 := httptest.NewRecorder()846 c1 := e.NewContext(req1, rec1)847 c1.SetPath("/player/:id/magicitems/:action")848 c1.SetParamNames("id", "action")849 c1.SetParamValues("5e70e4c5d2f3f777c16b29f8", "add")850 // Assertions851 if assert.NoError(t, AddOrRemoveMagicItems(c1)) {852 assert.Equal(t, http.StatusBadRequest, rec1.Code)853 }854 example2 := "{\"key\":\"value\"}"855 requestByte2, _ := json.Marshal(example2)856 requestReader2 := bytes.NewReader(requestByte2)857 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)858 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)859 rec2 := httptest.NewRecorder()860 c2 := e.NewContext(req2, rec2)861 c2.SetPath("/player/:id/magicitems/:action")862 c2.SetParamNames("id", "action")863 c2.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")864 // Assertions865 if assert.NoError(t, AddOrRemoveMagicItems(c2)) {866 assert.Equal(t, http.StatusBadRequest, rec2.Code)867 }868 example3 := rule.SimpleList{}869 requestByte3, _ := json.Marshal(example3)870 requestReader3 := bytes.NewReader(requestByte3)871 req3 := httptest.NewRequest(http.MethodPost, "/", requestReader3)872 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)873 rec3 := httptest.NewRecorder()874 c3 := e.NewContext(req3, rec3)875 c3.SetPath("/player/:id/magicitems/:action")876 c3.SetParamNames("id", "action")877 c3.SetParamValues("5e70e4c5d2f3f777c16b29f6", "delete")878 // Assertions879 if assert.NoError(t, AddOrRemoveMagicItems(c3)) {880 assert.Equal(t, http.StatusBadRequest, rec3.Code)881 }882 example4 := rule.SimpleList{}883 requestByte4, _ := json.Marshal(example4)884 requestReader4 := bytes.NewReader(requestByte4)885 req4 := httptest.NewRequest(http.MethodPost, "/", requestReader4)886 req4.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)887 rec4 := httptest.NewRecorder()888 c4 := e.NewContext(req4, rec4)889 c4.SetPath("/player/:id/magicitems/:action")890 c4.SetParamNames("id", "action")891 c4.SetParamValues("5e70e4c5d2f3f777c16b29f9", "add")892 // Assertions893 if assert.NoError(t, AddOrRemoveMagicItems(c4)) {894 assert.Equal(t, http.StatusBadRequest, rec4.Code)895 }896 example5 := rule.SimpleList{}897 requestByte5, _ := json.Marshal(example5)898 requestReader5 := bytes.NewReader(requestByte5)899 req5 := httptest.NewRequest(http.MethodPost, "/", requestReader5)900 req5.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)901 rec5 := httptest.NewRecorder()902 c5 := e.NewContext(req5, rec5)903 c5.SetPath("/player/:id/magicitems/:action")904 c5.SetParamNames("id", "action")905 c5.SetParamValues("5e70e4c5d2f3f777c16b29f6", "add")906 // Assertions907 if assert.NoError(t, AddOrRemoveMagicItems(c5)) {908 assert.Equal(t, http.StatusOK, rec5.Code)909 }910}...
gear_controller_test.go
Source:gear_controller_test.go
...15)16func TestGetAllWeapons(t *testing.T) {17 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)18 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)19 e := echo.New()20 req := httptest.NewRequest(http.MethodGet, "/", nil)21 rec := httptest.NewRecorder()22 c := e.NewContext(req, rec)23 c.SetPath("/rule/weapon")24 // Assertions25 if assert.NoError(t, GetAllWeapons(c)) {26 assert.Equal(t, http.StatusOK, rec.Code)27 }28 value1 := make(url.Values)29 value1["names"] = []string{"longsword"}30 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)31 rec1 := httptest.NewRecorder()32 c1 := e.NewContext(req1, rec1)33 c1.SetPath("/rule/weapon")34 // Assertions35 if assert.NoError(t, GetAllWeapons(c1)) {36 assert.Equal(t, http.StatusBadRequest, rec1.Code)37 }38}39func TestGetAllArmors(t *testing.T) {40 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)41 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)42 e := echo.New()43 req := httptest.NewRequest(http.MethodGet, "/", nil)44 rec := httptest.NewRecorder()45 c := e.NewContext(req, rec)46 c.SetPath("/rule/armor")47 // Assertions48 if assert.NoError(t, GetAllArmors(c)) {49 assert.Equal(t, http.StatusOK, rec.Code)50 }51 value1 := make(url.Values)52 value1["names"] = []string{"plate"}53 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)54 rec1 := httptest.NewRecorder()55 c1 := e.NewContext(req1, rec1)56 c1.SetPath("/rule/armor")57 // Assertions58 if assert.NoError(t, GetAllArmors(c1)) {59 assert.Equal(t, http.StatusBadRequest, rec1.Code)60 }61}62func TestGetAllGear(t *testing.T) {63 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)64 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)65 e := echo.New()66 req := httptest.NewRequest(http.MethodGet, "/", nil)67 rec := httptest.NewRecorder()68 c := e.NewContext(req, rec)69 c.SetPath("/rule/gear")70 // Assertions71 if assert.NoError(t, GetAllGear(c)) {72 assert.Equal(t, http.StatusOK, rec.Code)73 }74 value1 := make(url.Values)75 value1["names"] = []string{"something"}76 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)77 rec1 := httptest.NewRecorder()78 c1 := e.NewContext(req1, rec1)79 c1.SetPath("/rule/gear")80 // Assertions81 if assert.NoError(t, GetAllGear(c1)) {82 assert.Equal(t, http.StatusBadRequest, rec1.Code)83 }84}85func TestGetAllPacks(t *testing.T) {86 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)87 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)88 e := echo.New()89 req := httptest.NewRequest(http.MethodGet, "/", nil)90 rec := httptest.NewRecorder()91 c := e.NewContext(req, rec)92 c.SetPath("/rule/packs")93 // Assertions94 if assert.NoError(t, GetAllPacks(c)) {95 assert.Equal(t, http.StatusOK, rec.Code)96 }97 value1 := make(url.Values)98 value1["names"] = []string{"something"}99 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)100 rec1 := httptest.NewRecorder()101 c1 := e.NewContext(req1, rec1)102 c1.SetPath("/rule/packs")103 // Assertions104 if assert.NoError(t, GetAllPacks(c1)) {105 assert.Equal(t, http.StatusBadRequest, rec1.Code)106 }107}108func TestGetAllTools(t *testing.T) {109 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)110 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)111 e := echo.New()112 req := httptest.NewRequest(http.MethodGet, "/", nil)113 rec := httptest.NewRecorder()114 c := e.NewContext(req, rec)115 c.SetPath("/rule/tools")116 // Assertions117 if assert.NoError(t, GetAllTools(c)) {118 assert.Equal(t, http.StatusOK, rec.Code)119 }120 value1 := make(url.Values)121 value1["names"] = []string{"something"}122 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)123 rec1 := httptest.NewRecorder()124 c1 := e.NewContext(req1, rec1)125 c1.SetPath("/rule/tools")126 // Assertions127 if assert.NoError(t, GetAllTools(c1)) {128 assert.Equal(t, http.StatusBadRequest, rec1.Code)129 }130}131func TestGetAllMounts(t *testing.T) {132 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)133 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)134 e := echo.New()135 req := httptest.NewRequest(http.MethodGet, "/", nil)136 rec := httptest.NewRecorder()137 c := e.NewContext(req, rec)138 c.SetPath("/rule/mounts")139 // Assertions140 if assert.NoError(t, GetAllMounts(c)) {141 assert.Equal(t, http.StatusOK, rec.Code)142 }143 value1 := make(url.Values)144 value1["names"] = []string{"something"}145 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)146 rec1 := httptest.NewRecorder()147 c1 := e.NewContext(req1, rec1)148 c1.SetPath("/rule/mounts")149 // Assertions150 if assert.NoError(t, GetAllMounts(c1)) {151 assert.Equal(t, http.StatusBadRequest, rec1.Code)152 }153}154func TestCalcShop(t *testing.T) {155 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)156 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)157 e := echo.New()158 example := rule.SimpleList{159 List: []string{"horse"},160 }161 requestByte, _ := json.Marshal(example)162 requestReader := bytes.NewReader(requestByte)163 req := httptest.NewRequest(http.MethodPost, "/", requestReader)164 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)165 rec := httptest.NewRecorder()166 c := e.NewContext(req, rec)167 c.SetPath("/rule/shops")168 // Assertions169 if assert.NoError(t, CalcShop(c)) {170 assert.Equal(t, http.StatusOK, rec.Code)171 }172 example2 := "{\"key\":\"value\"}"173 requestByte2, _ := json.Marshal(example2)174 requestReader2 := bytes.NewReader(requestByte2)175 req2 := httptest.NewRequest(http.MethodPost, "/", requestReader2)176 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)177 rec2 := httptest.NewRecorder()178 c2 := e.NewContext(req2, rec2)179 c2.SetPath("/rule/shops")180 // Assertions181 if assert.NoError(t, CalcShop(c2)) {182 assert.Equal(t, http.StatusBadRequest, rec2.Code)183 }184}185func TestRandomTreasure(t *testing.T) {186 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)187 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)188 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)189 e := echo.New()190 req := httptest.NewRequest(http.MethodGet, "/", nil)191 rec := httptest.NewRecorder()192 c := e.NewContext(req, rec)193 c.SetPath("/rule/randomtreasure/:level")194 c.SetParamNames("level")195 c.SetParamValues("1")196 // Assertions197 if assert.NoError(t, RandomTreasure(c)) {198 assert.Equal(t, http.StatusOK, rec.Code)199 }200 req2 := httptest.NewRequest(http.MethodPost, "/", nil)201 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)202 rec2 := httptest.NewRecorder()203 c2 := e.NewContext(req2, rec2)204 c2.SetPath("/rule/randomtreasure/:level")205 c2.SetParamNames("level")206 c2.SetParamValues("a")207 // Assertions208 if assert.NoError(t, RandomTreasure(c2)) {209 assert.Equal(t, http.StatusBadRequest, rec2.Code)210 }211 req3 := httptest.NewRequest(http.MethodPost, "/", nil)212 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)213 rec3 := httptest.NewRecorder()214 c3 := e.NewContext(req3, rec3)215 c3.SetPath("/rule/randomtreasure/:level")216 c3.SetParamNames("level")217 c3.SetParamValues("31")218 // Assertions219 if assert.NoError(t, RandomTreasure(c3)) {220 assert.Equal(t, http.StatusBadRequest, rec3.Code)221 }222}223func TestFastTreasure(t *testing.T) {224 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)225 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)226 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)227 e := echo.New()228 req := httptest.NewRequest(http.MethodGet, "/", nil)229 rec := httptest.NewRecorder()230 c := e.NewContext(req, rec)231 c.SetPath("/rule/averagetreasure/:level")232 c.SetParamNames("level")233 c.SetParamValues("1")234 // Assertions235 if assert.NoError(t, FastTreasure(c)) {236 assert.Equal(t, http.StatusOK, rec.Code)237 }238 req2 := httptest.NewRequest(http.MethodPost, "/", nil)239 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)240 rec2 := httptest.NewRecorder()241 c2 := e.NewContext(req2, rec2)242 c2.SetPath("/rule/averagetreasure/:level")243 c2.SetParamNames("level")244 c2.SetParamValues("a")245 // Assertions246 if assert.NoError(t, FastTreasure(c2)) {247 assert.Equal(t, http.StatusBadRequest, rec2.Code)248 }249 req3 := httptest.NewRequest(http.MethodPost, "/", nil)250 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)251 rec3 := httptest.NewRecorder()252 c3 := e.NewContext(req3, rec3)253 c3.SetPath("/rule/averagetreasure/:level")254 c3.SetParamNames("level")255 c3.SetParamValues("31")256 // Assertions257 if assert.NoError(t, FastTreasure(c3)) {258 assert.Equal(t, http.StatusBadRequest, rec3.Code)259 }260}261func TestRandomTreasureHoard(t *testing.T) {262 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)263 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)264 appcontext.Current.Add(appcontext.Dice, test.InitDiceMock)265 e := echo.New()266 req := httptest.NewRequest(http.MethodGet, "/", nil)267 rec := httptest.NewRecorder()268 c := e.NewContext(req, rec)269 c.SetPath("/rule/treasurehoard/:level")270 c.SetParamNames("level")271 c.SetParamValues("1")272 // Assertions273 if assert.NoError(t, RandomTreasureHoard(c)) {274 assert.Equal(t, http.StatusOK, rec.Code)275 }276 req2 := httptest.NewRequest(http.MethodPost, "/", nil)277 req2.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)278 rec2 := httptest.NewRecorder()279 c2 := e.NewContext(req2, rec2)280 c2.SetPath("/rule/treasurehoard/:level")281 c2.SetParamNames("level")282 c2.SetParamValues("a")283 // Assertions284 if assert.NoError(t, RandomTreasureHoard(c2)) {285 assert.Equal(t, http.StatusBadRequest, rec2.Code)286 }287 req3 := httptest.NewRequest(http.MethodPost, "/", nil)288 req3.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)289 rec3 := httptest.NewRecorder()290 c3 := e.NewContext(req3, rec3)291 c3.SetPath("/rule/treasurehoard/:level")292 c3.SetParamNames("level")293 c3.SetParamValues("31")294 // Assertions295 if assert.NoError(t, RandomTreasureHoard(c3)) {296 assert.Equal(t, http.StatusBadRequest, rec3.Code)297 }298}299func TestGetAllServices(t *testing.T) {300 appcontext.Current.Add(appcontext.Database, test.InitDatabaseMock)301 appcontext.Current.Add(appcontext.Logger, test.InitMockLogger)302 e := echo.New()303 req := httptest.NewRequest(http.MethodGet, "/", nil)304 rec := httptest.NewRecorder()305 c := e.NewContext(req, rec)306 c.SetPath("/rule/services")307 // Assertions308 if assert.NoError(t, GetAllServices(c)) {309 assert.Equal(t, http.StatusOK, rec.Code)310 }311 value1 := make(url.Values)312 value1["names"] = []string{"something"}313 req1 := httptest.NewRequest(http.MethodGet, "/?"+value1.Encode(), nil)314 rec1 := httptest.NewRecorder()315 c1 := e.NewContext(req1, rec1)316 c1.SetPath("/rule/services")317 // Assertions318 if assert.NoError(t, GetAllServices(c1)) {319 assert.Equal(t, http.StatusBadRequest, rec1.Code)320 }321}...
New
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println("Error is:", err)5 }6 fmt.Println("Response is:", resp)7}8import (9func main() {10 if err != nil {11 fmt.Println("Error is:", err)12 }13 fmt.Println("Response is:", resp)14}
New
Using AI Code Generation
1func main() {2 if err != nil {3 log.Fatal(err)4 }5 defer resp.Body.Close()6 body, err := ioutil.ReadAll(resp.Body)7 if err != nil {8 log.Fatal(err)9 }10 fmt.Println(string(body))11}
New
Using AI Code Generation
1import (2func main() {3 fmt.Println("Starting the application...")4 http.HandleFunc("/", handler)5 http.ListenAndServe(":8080", nil)6}7func handler(w http.ResponseWriter, r *http.Request) {8 fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])9}10import (11func main() {12 fmt.Println("Starting the application...")13 http.HandleFunc("/hello", handler)14 http.ListenAndServe(":8080", nil)15}16func handler(w http.ResponseWriter, r *http.Request) {17 fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])18}19import (20func main() {21 fmt.Println("Starting the application...")22 http.HandleFunc("/hello", handler)23 http.ListenAndServe(":8080", http.DefaultServeMux)24}25func handler(w http.ResponseWriter, r *http.Request) {26 fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])27}28import (29func main() {30 fmt.Println("Starting the application...")31 http.HandleFunc("/hello", handler)32 http.ListenAndServe(":8080", http.DefaultServeMux)33}34func handler(w http.ResponseWriter, r *http.Request) {35 fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])36}37import (38func main()
New
Using AI Code Generation
1import (2func main() {3 client := &http.Client{}4 if err != nil {5 }6 resp, err := client.Do(req)7 if err != nil {8 }9 fmt.Println(resp)10}11Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.812Accept-Language: en-US,en;q=0.513User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.114import (15func main() {16 if err != nil {17 }18 fmt.Println(resp)19}20Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.821Accept-Language: en-US,en;q=0.522User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1
New
Using AI Code Generation
1import (2func main() {3 if err != nil {4 }5 client := &http.Client{}6 resp, err := client.Do(req)7 if err != nil {8 }9 defer resp.Body.Close()10 fmt.Println("response Status:", resp.Status)11 fmt.Println("response Headers:", resp.Header)12}13response Headers: map[Alt-Svc:[quic=":443"; ma=2592000; v="46,44,43,39"], Cache-Control:[private, max-age=0], Content-Encoding:[gzip], Content-Type:[text/html; charset=ISO-8859-1], Date:[Fri, 13 May 2016 06:18:48 GMT], Expires:[-1], P3p:[CP="This is not a P3P policy! See g.co/p3phelp for more inf
New
Using AI Code Generation
1if err != nil {2 panic(err)3}4defer resp.Body.Close()5body, err := ioutil.ReadAll(resp.Body)6if err != nil {7 panic(err)8}9fmt.Println(string(body))10if err != nil {11 panic(err)12}13defer resp.Body.Close()14body, err := ioutil.ReadAll(resp.Body)15if err != nil {16 panic(err)17}18fmt.Println(string(body))19if err != nil {20 panic(err)21}22defer resp.Body.Close()23body, err := ioutil.ReadAll(resp.Body)24if err != nil {25 panic(err)26}27fmt.Println(string(body))28if err != nil {29 panic(err)30}31defer resp.Body.Close()32body, err := ioutil.ReadAll(resp.Body)33if err != nil {34 panic(err)35}36fmt.Println(string(body))37if err != nil {38 panic(err)39}40defer resp.Body.Close()41body, err := ioutil.ReadAll(resp.Body)42if err != nil {43 panic(err)44}45fmt.Println(string(body))46if err != nil {47 panic(err)48}49defer resp.Body.Close()50body, err := ioutil.ReadAll(resp.Body)51if err != nil {52 panic(err)53}54fmt.Println(string(body))55if err != nil {56 panic(err)57}58defer resp.Body.Close()59body, err := ioutil.ReadAll(resp
New
Using AI Code Generation
1resp, err := http.DefaultClient.Do(req)2body, err := ioutil.ReadAll(resp.Body)3fmt.Println(string(body))4body, err := ioutil.ReadAll(resp.Body)5fmt.Println(string(body))6body, err := ioutil.ReadAll(resp.Body)7fmt.Println(string(body))8body, err := ioutil.ReadAll(resp.Body)9fmt.Println(string(body))10body, err := ioutil.ReadAll(resp.Body)11fmt.Println(string(body))12body, err := ioutil.ReadAll(resp.Body)13fmt.Println(string(body))
New
Using AI Code Generation
1import (2func main() {3 if err != nil {4 panic(err)5 }6 resp, err := http.DefaultClient.Do(req)7 if err != nil {8 panic(err)9 }10 defer resp.Body.Close()11 body, err := ioutil.ReadAll(resp.Body)12 if err != nil {13 panic(err)14 }15 var dat map[string]interface{}16 if err := json.Unmarshal(body, &dat); err != nil {17 panic(err)18 }19 println(dat["name"].(string))20 println(dat["age"].(float64))21}22import (23func main() {24 if err != nil {25 panic(err)26 }27 defer resp.Body.Close()28 body, err := ioutil.ReadAll(resp.Body)29 if err != nil {30 panic(err)31 }32 var dat map[string]interface{}33 if err := json.Unmarshal(body, &dat); err != nil {34 panic(err)35 }36 println(dat["name"].(string))37 println(dat["age"].(float64))38}
New
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println("Error:", err)5 }6 client := &http.Client{}7 resp, err := client.Do(req)8 if err != nil {9 fmt.Println("Error:", err)10 }11 fmt.Println("Response Status:", resp.Status)12}13import (14func main() {15 if err != nil {16 fmt.Println("Error:", err)17 }18 fmt.Println("Response Status:", resp.Status)19}20import (21func main() {22 if err != nil {23 fmt.Println("Error:", err)24 }25 fmt.Println("Response Status:", resp.Status)26}27import (28func main() {29 form := url.Values{}30 form.Add("username", "admin")31 form.Add("password", "admin123")32 if err != nil {33 fmt.Println("Error:", err)34 }
New
Using AI Code Generation
1import (2func main() {3 if err != nil {4 fmt.Println("Error:", err)5 }6 fmt.Println("Response:", resp)7}8Response: &{200 OK 200 HTTP/1.1 1 1 map[Content-Type:[text/plain; charset=utf-8] Date:[Wed, 23 Aug 2017 12:11:21 GMT] Expires:[-1] X-Content-Type-Options:[nosniff] Content-Length:[35] X-XSS-Protection:[1; mode=block]] 0xc04200e3c0 35 [] false false map[] 0xc04200e3c0 <nil>}9import (10func main() {11 if err != nil {12 fmt.Println("Error:", err)13 }14 fmt.Println("Request:", req)15}16import (17func main() {18 if err != nil {19 fmt.Println("Error:", err)20 }21 fmt.Println("Request:", req)22}23import (24func main() {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!