All files / src/endpoint/html logout.ts

35.71% Statements 5/14
100% Branches 0/0
0% Functions 0/3
35.71% Lines 5/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36  2x 2x 2x 2x                                                           2x  
import Node from 'type/node';
import HttpHeader from 'http/enum/header';
import buildCookie from 'http/utility/build-cookie';
import HtmlEndpoint from 'endpoint/html';
import LogoutPageTemplate from 'template/page/logout';
 
class HtmlLogoutEndpoint extends HtmlEndpoint<Record<string, never>> {
	protected async process(): Promise<string> {
		this.clearCookie();
 
		const account = await this.loadAnonymousAccount();
 
		const template = new LogoutPageTemplate({
			account
		});
 
		const html = template.render();
 
		return Promise.resolve(html);
	}
 
	private clearCookie(): void {
		const cookie = buildCookie('', 0);
 
		this.setHeaderValue(HttpHeader.SET_COOKIE, cookie);
	}
 
	private loadAnonymousAccount(): Promise<Node> {
		const repository = this.getRepository();
 
		return repository.fetchAnonymousAccount();
	}
}
 
export default HtmlLogoutEndpoint;