Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-4100 - Using Public API (SHD) to Create Test School #132

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions create-school.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const SHD_URL = process.env.SHD_URL;

const SHD_BASICAUTH_LOGIN = process.env.SHD_BASICAUTH_LOGIN;
const SHD_BASICAUTH_PASSWORD = process.env.SHD_BASICAUTH_PASSWORD;

const SHD_LOGIN = process.env.SHD_LOGIN;
const SHD_PASSWORD = process.env.SHD_PASSWORD;

const login = async () => {
const response = await fetch(`${SHD_URL}/login/`, {
method: 'POST',
redirect: 'manual',
follow: 10,
headers: {
'authorization': 'basic ' + Buffer.from(SHD_BASICAUTH_LOGIN + ":" + SHD_BASICAUTH_PASSWORD).toString('base64'),
'content-type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
email: SHD_LOGIN,
password: SHD_PASSWORD,
}).toString(),
});

const cookies = response.headers.get('set-cookie');
const jwt = cookies.match(/jwt=([^;]*)/)[1];

return jwt;
}

const createSchool = async (jwt) => {
const response = await fetch(`${SHD_URL}/schools/`, {
method: 'POST',
redirect: 'manual',
follow: 10,
headers: {
'authorization': 'basic ' + Buffer.from(SHD_BASICAUTH_LOGIN + ":" + SHD_BASICAUTH_PASSWORD).toString('base64'),
'content-type': 'application/x-www-form-urlencoded',
'cookie': `jwt=${jwt}`,
},
body: new URLSearchParams({
name: 'Test-Oberschule-4',
fileStorageType: 'awsS3',
password: SHD_PASSWORD,
officialSchoolNumber: '',
ldapSchoolIdentifier: '',
}).toString(),
});

console.log("Status:", response.status);
const data = await response.text();
console.log(data);

return response.status;
}

(async () => {
const jwt = await login();
console.log(jwt);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:P

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that looks scary :-) But it's in the client code and for testing purposes only. Apart from that we're gonna close this PR in favor of hpi-schul-cloud/schulcloud-server#4365

await createSchool(jwt);
})();