Compare commits

...

2 commits

Author SHA1 Message Date
cc8ad713a7 Test & Remove debug for Theo 2023-09-18 08:47:55 +02:00
e50034dd00 little test for groups 2023-09-18 08:46:11 +02:00
4 changed files with 89 additions and 1 deletions

Binary file not shown.

View file

@ -123,4 +123,5 @@ CREATE TABLE `containsTags` (
CONSTRAINT `containsTags_ibfk_2` FOREIGN KEY (`fk_puzzle`) REFERENCES `puzzles` (`id_puzzle`) CONSTRAINT `containsTags_ibfk_2` FOREIGN KEY (`fk_puzzle`) REFERENCES `puzzles` (`id_puzzle`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO chapters (id_chapter, name) VALUES (1, 'chapter 1');
INSERT INTO players (pseudo, email, passwd,firstname,lastname) VALUES ('userTest', 'test@peerat.dev', '$argon2id$v=19$m=15360,t=2,p=1$$cAQwfs30Bf2rQGj86bpz7i59TlsuOFPiXeNpLlVu4AY', 'a','b')

View file

@ -98,6 +98,10 @@ public class WebClient {
this.writer.write(type+" "+route+" HTTP/1.1\n"); this.writer.write(type+" "+route+" HTTP/1.1\n");
if(this.token != null) this.writer.write("Authorization: Bearer "+this.token+"\n"); if(this.token != null) this.writer.write("Authorization: Bearer "+this.token+"\n");
for(String send : this.sendHeaders) this.writer.write(send+"\n"); for(String send : this.sendHeaders) this.writer.write(send+"\n");
int length = 0;
for(String value : content) length+=value.length();
length+=content.length-1;
this.writer.write("Content-length: "+length+"\n");
this.writer.write("\n"); this.writer.write("\n");
for(String value : content) this.writer.write(value+"\n"); for(String value : content) this.writer.write(value+"\n");

View file

@ -0,0 +1,83 @@
package dev.peerat.backend.userstories;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import dev.peerat.backend.Main;
import dev.peerat.backend.WebClient;
import dev.peerat.framework.utils.json.JsonMap;
@TestInstance(Lifecycle.PER_METHOD)
public class GroupTests extends BaseUserStoriesTest{
private Thread server;
private WebClient client;
@BeforeEach
public void init() throws Exception{
Class.forName("com.mysql.cj.jdbc.Driver");
super.init();
getRepository().init();
getRepository().reset();
server = new Thread(new Runnable(){
@Override
public void run(){
try {
Main.main(null);
} catch (Exception e){
e.printStackTrace();
};
}
});
server.start();
client = new WebClient("localhost", 80);
// System.out.println(Password.hash("password").withArgon2().getResult());
try {
client.auth("userTest", "password");
client.assertResponseCode(200);
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterEach
public void stop(){
server.interrupt();
}
@Test
void createNormalGroup() throws Exception{
JsonMap json = new JsonMap();
json.set("name", "Group_test");
json.set("chapter", 1);
client.route("/groupCreate", "POST", json.toString());
client.assertResponseCode(200);
}
@Test
void leaveNormalGroup() throws Exception{
createNormalGroup();
JsonMap json = new JsonMap();
json.set("name", "Group_test");
json.set("chapter", 1);
client.route("/groupQuit", "POST", json.toString());
client.assertResponseCode(200);
}
@Test
void joinNormalGroup() throws Exception{
leaveNormalGroup();
JsonMap json = new JsonMap();
json.set("name", "Group_test");
json.set("chapter", 1);
client.route("/groupJoin", "POST", json.toString());
client.assertResponseCode(200);
}
}