All files / src/system node-generator.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 4/4
100% Lines 10/10

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 37 38 39 40 41 42 43 44 45 46 47  24x 24x           478x       477x                     478x 478x 478x   478x             478x                     24x  
import Node from 'type/node';
import SystemId from 'system/enum/id';
import buildNodeUrl from 'utility/build-node-url';
 
abstract class SystemNodeGenerator {
	private hostname: string;
 
	public constructor(hostname: string) {
		this.hostname = hostname;
	}
 
	public generate(): Node {
		return {
			id: this.getNodeId(),
			type_id: this.getTypeId(),
			creator: this.getCreator(),
			created_at: 0,
			updated_at: 0,
			changes: []
		};
	}
 
	protected getCreator(): string {
		const hostname = this.getHostname();
		const id = SystemId.SYSTEM_ACCOUNT;
		const type_id = SystemId.ACCOUNT_TYPE;
 
		return buildNodeUrl(hostname, {
			id,
			type_id
		});
	}
 
	private getHostname(): string {
		return this.hostname;
	}
 
	protected abstract getTypeId(): string;
	protected abstract getNodeId(): string;
}
 
export interface GeneratorConstructor {
	new (hostname: string): SystemNodeGenerator;
}
 
export default SystemNodeGenerator;