From f66a9fa7f132f41b2e40029f0fb535521c3fb716 Mon Sep 17 00:00:00 2001 From: jw255 Date: Sat, 24 Feb 2018 17:13:43 +0000 Subject: restructuring of tests + yarn install script --- coverage/project-code/src/FileRouter.ts.html | 1769 ++++++++++++++++++++ coverage/project-code/src/app.ts.html | 197 +++ coverage/project-code/src/db/index.html | 106 ++ .../project-code/src/db/initPostgresDB.ts.html | 110 ++ .../src/db/model/ContributorGroup.ts.html | 227 +++ coverage/project-code/src/db/model/File.ts.html | 206 +++ coverage/project-code/src/db/model/Project.ts.html | 290 ++++ coverage/project-code/src/db/model/User.ts.html | 299 ++++ .../project-code/src/db/model/UserGroup.ts.html | 221 +++ .../src/db/model/UserJoinsProject.ts.html | 146 ++ coverage/project-code/src/db/model/index.html | 158 ++ coverage/project-code/src/db/orm.ts.html | 101 ++ coverage/project-code/src/index.html | 93 + coverage/project-code/src/index.ts.html | 227 +++ coverage/project-code/src/matcher/index.html | 106 ++ coverage/project-code/src/matcher/options.ts.html | 362 ++++ .../src/matcher/options.unit.test.ts.html | 554 ++++++ coverage/project-code/src/matcher/types.ts.html | 302 ++++ .../src/matcher/types.unit.test.ts.html | 599 +++++++ coverage/project-code/src/serverConfig.ts.html | 473 ++++++ 20 files changed, 6546 insertions(+) create mode 100644 coverage/project-code/src/FileRouter.ts.html create mode 100644 coverage/project-code/src/app.ts.html create mode 100644 coverage/project-code/src/db/index.html create mode 100644 coverage/project-code/src/db/initPostgresDB.ts.html create mode 100644 coverage/project-code/src/db/model/ContributorGroup.ts.html create mode 100644 coverage/project-code/src/db/model/File.ts.html create mode 100644 coverage/project-code/src/db/model/Project.ts.html create mode 100644 coverage/project-code/src/db/model/User.ts.html create mode 100644 coverage/project-code/src/db/model/UserGroup.ts.html create mode 100644 coverage/project-code/src/db/model/UserJoinsProject.ts.html create mode 100644 coverage/project-code/src/db/model/index.html create mode 100644 coverage/project-code/src/db/orm.ts.html create mode 100644 coverage/project-code/src/index.html create mode 100644 coverage/project-code/src/index.ts.html create mode 100644 coverage/project-code/src/matcher/index.html create mode 100644 coverage/project-code/src/matcher/options.ts.html create mode 100644 coverage/project-code/src/matcher/options.unit.test.ts.html create mode 100644 coverage/project-code/src/matcher/types.ts.html create mode 100644 coverage/project-code/src/matcher/types.unit.test.ts.html create mode 100644 coverage/project-code/src/serverConfig.ts.html (limited to 'coverage/project-code/src') diff --git a/coverage/project-code/src/FileRouter.ts.html b/coverage/project-code/src/FileRouter.ts.html new file mode 100644 index 0000000..e1704c6 --- /dev/null +++ b/coverage/project-code/src/FileRouter.ts.html @@ -0,0 +1,1769 @@ + + + + Code coverage report for project-code/src/FileRouter.ts + + + + + + + +
+
+

+ All files / project-code/src FileRouter.ts +

+
+
+ 44.53% + Statements + 57/128 +
+
+ 0% + Branches + 0/22 +
+
+ 5.41% + Functions + 2/37 +
+
+ 47.9% + Lines + 57/119 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 +460 +461 +462 +463 +464 +465 +466 +467 +468 +469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 +480 +481 +482 +483 +484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +501 +502 +503 +504 +505 +506 +507 +508 +509 +510 +511 +512 +513 +514 +515 +516 +517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 +548 +549 +550 +551 +552 +553 +554 +555 +556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +5691x +  +1x +1x +1x +1x +  +1x +1x +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +1x +  +  +  +  +  +  +1x +1x +  +  +  +  +  +  +  +  +2x +2x +2x +2x +2x +  +2x +2x +2x +2x +2x +2x +2x +  +2x +2x +2x +2x +2x +  +2x +2x +2x +  +  +  +  +1x +1x +  +1x +1x + 
import { ContributorGroupFullInfo, default as ContributorGroup
+	} from './db/model/ContributorGroup';
+import { default as File } from './db/model/File';
+import { ProjectFullInfo, default as Project } from './db/model/Project';
+import { UserFullInfo, default as User } from './db/model/User';
+import { default as UserGroup } from './db/model/UserGroup';
+ 
+import { NextFunction, Request, Response, Router } from 'express';
+import { default as serverConfig } from './serverConfig';
+ 
+// TODO: figure this out
+const BASE_FILE_STORAGE: string = 'TODO: figure this out';
+ 
+/**
+ * The type of an Express middleware callback.
+ */
+type Middleware =
+	(req: Request, res: Response, next: NextFunction) => void;
+ 
+/**
+ * Returns the supported Protocols
+ *
+ * The server's unwrapped response MUST match:
+ *
+ * exactly({
+ *     "supported": array(string),
+ *     "required": array(string)
+ * })
+ */
+const getProtocols: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	const returnValue: {
+		supported: string[];
+		required: string[];
+	} = {
+	supported: [],
+	required: [
+		'BE01'
+	]
+	};
+	res.send(JSON.stringify(returnValue));
+};
+ 
+/**
+ * Logging Endpoint for all components:
+ *
+ * with a request matching
+ *
+ * array({
+ *     "component": string,
+ *     "level": alternative([
+ *         "info",
+ *         "security",
+ *         "warning",
+ *         "error",
+ *         "critical"
+ *     ]),
+ *     "value": anything
+ * })
+ */
+const postLog: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.status(501)
+		.send({error : 'logging_not_enabled'});
+};
+ 
+/**
+ * Clients authorised as a user with the admin privilege can access
+ *
+ * http://backend.endpoint/log?before=<datetime>&after=<datetime>&level=<level>
+ *
+ * the server response should match
+ *
+ * array({
+ *     "component": string,
+ *     "level": alternative([
+ *         "info",
+ *         "security",
+ *         "warning",
+ *         "error",
+ *         "critical"
+ *     ]),
+ *     "value": anything,
+ *     "username": string,
+ *     "timestamp": string
+ * })
+ */
+const getLog: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.status(501)
+		.send({error : 'logging_not_enabled'});
+};
+ 
+/**
+ * Any authenticated client can access
+ *
+ * http://backend.endpoint/properties
+ *
+ * the server SHOULD respond with a list of properties,
+ * with the unwrapped response matching
+ *
+ * array({
+ *     "id": string,
+ *     "display": optional({
+ *         "category": string,
+ *         "group": string,
+ *         "display_name": string,
+ *         "description": string
+ *     }),
+ *     "read_only": boolean,
+ *     "type": alternative(["string", "integer", "boolean"]),
+ *     "value": alternative([string, integer, boolean])
+ * })
+ */
+const getProperties: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.status(200)
+		.send(serverConfig);
+};
+ 
+/**
+ * To update properties the client POSTs to
+ *
+ * http://backend.endpoint/properties?action=update
+ *
+ * with body
+ *
+ * array({
+ *     "id": string,
+ *     "value": alternative([string, integer, boolean])
+ * })
+ */
+const postProperties: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	let success: boolean = true;
+ 
+	// For each property to update
+	for (const prop of req.body) {
+ 
+		// Check that the property has and id and a value
+		if (!prop.hasOwnProperty('id') || !prop.hasOwnProperty('value')) {
+			res.status(400)
+				.send({
+					error: 'invalid_request',
+					error_description: 'A supplied property is missing an id or value'
+				});
+			success = false;
+			break;
+		}
+ 
+		// Find out if the property exists in the config and if so, at which index
+		const index: number = serverConfig.indexOf(prop.id);
+ 
+		// Check some of the properties values to ensure that it can be updated
+		if (index === -1 || serverConfig[index].readOnly) {
+			/* TODO Implement an or, using Tom's type checker
+			 * to ensure the value is "valid" based on the type of the property */
+			const description: string = index === -1
+				? 'Property not found'
+				: 'Property is Read_Only';
+			res.status(400)
+				.send({
+				error: 'invalid_property',
+				error_data: prop.id,
+				error_description: description
+			});
+			success = false;
+			break;
+		}
+ 
+		// Make the update to the property
+		serverConfig[index].value = prop.value;
+	}
+ 
+	// Tell the client that everything was okay;
+	if (success) {
+		res.status(200)
+			.send();
+	}
+};
+ 
+/**
+ * Listing available privileges
+ *
+ * And the server's response, unwrapped, must match
+ *
+ * array({
+ *     "privilege": string,
+ *     "description": string,
+ *     "internal": boolean
+ * })
+ */
+const getUserPriveleges: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const usergroups: UserGroup[] = await UserGroup.findAll();
+	res.json(usergroups.map(
+		(ug: UserGroup) => ug.getPrivelege()
+	));
+};
+ 
+/**
+ * Listing users
+ *
+ * If the client is authorised as a user with the admin privilege
+ * the server MUST respond with a list of users,
+ * with the unwrapped response matching
+ *
+ * array({
+ *     "username": string,
+ *     "privileges": array(string),
+ *     "projects": array({
+ *         "project_name": string,
+ *         "access_level": string
+ *     }),
+ *     "public_user_metadata": metadata,
+ *     "private_user_metadata": metadata,
+ *     "public_admin_metadata": metadata,
+ *     "private_admin_metadata": metadata
+ * })
+ */
+const getUsers: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const users: User[] = await User.findAll({
+		include: [
+			UserGroup,
+			Project
+		]
+	});
+	res.json(users.map<UserFullInfo>(
+		(u: User) => u.getUserFullInfo()
+	));
+};
+ 
+/**
+ * Expose additional configuration options for individual users
+ */
+const getUserProperties: Middleware =
+	(req: Request, res: Response, next: NextFunction, user?: string): void => {
+	res.status(500)
+	.send({
+		error: 'unsupported',
+		error_description:
+			'Users on this server dont have additional configuration options.'
+	});
+};
+ 
+const userInfoFromName: (name: string) => Promise<UserFullInfo> =
+	async(name: string): Promise<UserFullInfo> =>  {
+	const user: User | null = await User.findOne({
+		where: {
+			username: name
+		},
+		include: [
+			UserGroup,
+			Project
+		]
+	});
+ 
+	if (user === null) {
+		throw new Error(`No user of name ${name} in database.`);
+	} else {
+		return user.getUserFullInfo();
+	}
+};
+ 
+/**
+ * Listing a particular User
+ *
+ * If the client is authorised as a user with the admin privilege
+ * the server MUST respond with details of the particular user if they exist
+ * (unwrapped response):
+ *
+ * {
+ *     "username": string,
+ *     "privileges": array(string),
+ *     "projects": array({
+ *         "project_name": string,
+ *         "access_level": string
+ *     }),
+ *     "public_user_metadata": metadata,
+ *     "private_user_metadata": metadata,
+ *     "public_admin_metadata": metadata,
+ *     "private_admin_metadata": metadata
+ * }
+ */
+const getUsername: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const info: UserFullInfo = await userInfoFromName(req.params.username);
+	res.json(info);
+};
+ 
+const getCurUser: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.json({
+		todo: 'need to findo out where authenticated user info goes'
+	});
+};
+ 
+/**
+ * Updating the current user
+ *
+ * http://backend.endpoint/current_user?action=update
+ *
+ * with body matching
+ *
+ * {
+ *     "password": optional({
+ *         "old": string,
+ *         "new": string
+ *     }),
+ *     "public_user_metadata": optional(metadata),
+ *     "private_user_metadata": optional(metadata),
+ *     "public_admin_metadata": not_present,
+ *     "private_admin_metadata": not_present
+ * }
+ */
+const postCurUser: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.json({todo: 'need to implement meeeee'});
+};
+ 
+/**
+ * Creating a User/updating a user
+ *
+ * http://backend.endpoint/users/<username>?action=create
+ *
+ * with body matching
+ *
+ * {
+ *     "privileges": array(string),
+ *     "password": string,
+ *     "public_user_metadata": optional(metadata),
+ *     "private_user_metadata": optional(metadata),
+ *     "public_admin_metadata": optional(metadata),
+ *     "private_admin_metadata": optional(metadata)
+ * }
+ */
+const postUsername: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.json({todo: 'need to implement meeeee'});
+};
+ 
+/**
+ * Listing available Roles
+ *
+ * The servers response, unwrapped, must match
+ *
+ * array({
+ *     "role": string,
+ *     "description": string,
+ *     "internal": boolean
+ * })
+ */
+const getProjectRoles: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const roles: ContributorGroup[] = await ContributorGroup.findAll();
+	res.json(roles.map<ContributorGroupFullInfo>(
+		(cg: ContributorGroup) => cg.getContributorGroupFullInfo()
+	));
+};
+ 
+/**
+ * Listing Projects
+ *
+ * The server MUST respond with a list of projects,
+ * with the unwrapped response matching
+ *
+ * array({
+ *     "project_name": string,
+ *     "users": array({
+ *         "username": string,
+ *         "access_level": string
+ *     }),
+ *     "public_metadata": metadata,
+ *     "private_metadata": optional(metadata),
+ *     "admin_metadata": optional(metadata)
+ * })
+ */
+const getProjects: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const projects: Project[] = await Project.findAll({
+		include: [
+			User
+		]
+	});
+	res.json(projects.map<ProjectFullInfo>(
+		(p: Project) => p.getProjectFullInfo()
+	));
+};
+ 
+/**
+ * Listing a specific Project
+ *
+ * The server MUST respond with details of the particular project
+ * if it exists (unwrapped response):
+ *
+ * {
+ *     "project_name": string,
+ *     "users": array({
+ *         "username": string,
+ *         "access_level": string
+ *     }),
+ *     "public_metadata": metadata,
+ *     "private_metadata": metadata,
+ *     "admin_metadata": optional(metadata)
+ * }
+ */
+const getProjectName: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const project: Project | null = await Project.findOne({
+		where: {
+			name: req.params.project_name
+		}
+	});
+	if (project === null) {
+		throw new Error(`Project ${req.params.project_name} does not exist`);
+	} else {
+		res.json(project);
+	}
+};
+ 
+/**
+ * Creating a Project / updating a project / deleting / Project grants
+ *
+ * http://backend.endpoint/projects/<project_name>?action=create
+ *
+ * with body matching
+ *
+ * {
+ *     "public_metadata": optional(metadata),
+ *     "private_metadata": optional(metadata),
+ *     "admin_metadata": optional(metadata)
+ * }
+ */
+const postProjectName: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.json({todo: 'need to implement meeeee'});
+};
+ 
+/*
+ * additional configuration options for individual projects
+ */
+const getProjectProperties: Middleware =
+	(req: Request, res: Response, next: NextFunction): void => {
+	res.status(500)
+	.send({
+		error: 'unsupported',
+		error_description:
+			'Projects on this server dont have additional configuration options.'
+	});
+};
+ 
+const getChildFile: (names: string[], parentUuid: string) => Promise<File> =
+	async(names: string[], parentUuid: string): Promise<File> => {
+	// TODO: Check that this works lol :3
+	const child: File | null = await File.findOne({
+		where: {
+			parentFolderId: parentUuid,
+			name: names[0]
+		}
+	});
+ 
+	if (child === null) {
+		throw new Error(`File of name ${names[0]} does not exist`);
+	} else {
+		if (names.length === 1) {
+			return child;
+		} else {
+			names.splice(0, 1);
+			return getChildFile(names, child.uuid);
+		}
+	}
+};
+ 
+/**
+ * GET a File.
+ */
+const getFilePath: Middleware =
+	async(req: Request, res: Response, next: NextFunction): Promise<void> => {
+	const project: Project | null = await Project.findOne({
+		where: {
+			name: req.params.project_name
+		}
+	});
+ 
+	if (project === null) {
+		throw new Error(
+			`Project of name ${req.params.project_name} does not exist`
+		);
+	} else {
+		const file: File = await getChildFile(
+			req.params.project_name, project.rootFolderId
+		);
+ 
+		res.sendFile(
+			`${BASE_FILE_STORAGE}/${req.params.project_name}/${file.uuid}`
+		);
+	}
+};
+ 
+/**
+ * GET a File.
+ */
+const getFileId: Middleware =
+	(req: Request, res: Response, next: NextFunction): void =>  {
+	// TODO: implement correctness of project folder checking.
+	res.sendFile(
+		`${BASE_FILE_STORAGE}/${req.params.project_name}/${req.params.id}`
+	);
+};
+ 
+/**
+ * Post a File. / delete / move / etc
+ */
+const postFilePath: Middleware =
+	(req: Request, res: Response, next: NextFunction): void =>  {
+	res.json({todo: 'need to implement meeeee'});
+};
+ 
+export class FileRouter {
+	public router: Router;
+ 
+	/**
+	 * Initialize the FileRouter
+	 */
+	public constructor() {
+	this.router = Router();
+	this.init();
+	}
+ 
+	/**
+	 * Take each handler, and attach to one of the Express.Router's
+	 * endpoints.
+	 */
+	public init(): void {
+		// General
+		this.router.get ('/_supported_protocols_',	                   getProtocols);
+		this.router.get ('/log',						                     getLog);
+		this.router.post('/log',	       									postLog);
+		this.router.get ('/properties',						          getProperties);
+		this.router.post('/properties',						         postProperties);
+		// Users
+		this.router.get ('/user_privileges',				      getUserPriveleges);
+		this.router.get ('/users',									       getUsers);
+		this.router.get ('/users/:username',				            getUsername);
+		this.router.post('/users/:username',				           postUsername);
+		this.router.get ('/users/:username/properties',           getUserProperties);
+		this.router.get ('/current_user',					             getCurUser);
+		this.router.post('/current_user',					            postCurUser);
+		// Projects
+		this.router.get ('/project_roles',					        getProjectRoles);
+		this.router.get ('/projects',							        getProjects);
+		this.router.get ('/projects/:project_name',                  getProjectName);
+		this.router.post('/projects/:project_name',                 postProjectName);
+		this.router.get ('/projects/:project_name/properties', getProjectProperties);
+		// File access
+		this.router.get ('/projects/:project_name/files/:path',         getFilePath);
+		this.router.post('/projects/:project_name/files/:id',          postFilePath);
+		this.router.get ('/projects/:project_name/files_by_id/:id',       getFileId);
+	}
+}
+ 
+// Create the FileRouter, and export its configured Express.Router
+const fileRoutes: FileRouter = new FileRouter();
+fileRoutes.init();
+ 
+const ex: Router = fileRoutes.router;
+export default ex;
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/app.ts.html b/coverage/project-code/src/app.ts.html new file mode 100644 index 0000000..60f3e87 --- /dev/null +++ b/coverage/project-code/src/app.ts.html @@ -0,0 +1,197 @@ + + + + Code coverage report for project-code/src/app.ts + + + + + + + +
+
+

+ All files / project-code/src app.ts +

+
+
+ 90.48% + Statements + 19/21 +
+
+ 50% + Branches + 1/2 +
+
+ 100% + Functions + 5/5 +
+
+ 90.48% + Lines + 19/21 +
+
+
+
+

+
+
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 +451x +1x +1x +1x +  +  +  +  +  +  +2x +2x +2x +2x +  +  +  +  +2x +  +  +  +2x +2x +  +  +  +  +2x +2x +3x +  +  +  +  +2x +2x +  +  +  +1x +1x +1x +  + 
import * as bodyParser from 'body-parser';
+import * as ex from 'express';
+import FileRouter from './FileRouter';
+import * as logger from 'morgan';
+ 
+class App {
+	public express: ex.Express;
+	private logEnabled: boolean;
+ 
+	public constructor(enableLog: boolean) {
+		this.express = ex();
+		this.middleware();
+		this.mountRoutes();
+		this.logEnabled = enableLog;
+	}
+ 
+	// Configure Express middleware.
+	private middleware(): void {
+		Iif (this.logEnabled) {
+			console.log("log enabled")
+			this.express.use(logger('combined'));
+		}
+		this.express.use(bodyParser.json());
+		this.express.use(bodyParser.urlencoded({ extended: false }));
+	}
+ 
+	// Configure API endpoints.
+	private mountRoutes(): void {
+		const defRouter: ex.Router = ex.Router();
+		defRouter.get('/', (req: ex.Request, res: ex.Response): void => {
+			res.json({
+				message: 'Welcome to the CS3099 BE4 server!',
+				important : 'Endpoints start from /cs3099group-be-4/'
+			});
+		});
+		this.express.use('/', defRouter);
+		this.express.use('/cs3099group-be-4', FileRouter);
+	}
+}
+ 
+export default new App(true).express;
+export function TestApp(){
+	return new App(false).express;
+} 
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/index.html b/coverage/project-code/src/db/index.html new file mode 100644 index 0000000..a7d063a --- /dev/null +++ b/coverage/project-code/src/db/index.html @@ -0,0 +1,106 @@ + + + + Code coverage report for project-code/src/db + + + + + + + +
+
+

+ All files project-code/src/db +

+
+
+ 0% + Statements + 0/3 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/2 +
+
+ 0% + Lines + 0/3 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
initPostgresDB.ts
0%0/2100%0/00%0/20%0/2
orm.ts
0%0/1100%0/0100%0/00%0/1
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/initPostgresDB.ts.html b/coverage/project-code/src/db/initPostgresDB.ts.html new file mode 100644 index 0000000..35036ff --- /dev/null +++ b/coverage/project-code/src/db/initPostgresDB.ts.html @@ -0,0 +1,110 @@ + + + + Code coverage report for project-code/src/db/initPostgresDB.ts + + + + + + + +
+
+

+ All files / project-code/src/db initPostgresDB.ts +

+
+
+ 0% + Statements + 0/2 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/2 +
+
+ 0% + Lines + 0/2 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import * as Sequelize from 'sequelize';
+const gres: Sequelize.Sequelize = new Sequelize(
+	'postgres://admin:eprprJacR0hBpmWvs5IDJZTnjRAY2gM3tSm0b1af@localhost:5432/be4',
+	{
+		operatorsAliases : false
+	}
+);
+ 
+gres.authenticate()
+	.then(() => {
+		// Connection has been established successfully.
+	})
+	.catch((err: Error) => {
+		// Unable to connect to the database.
+	});
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/ContributorGroup.ts.html b/coverage/project-code/src/db/model/ContributorGroup.ts.html new file mode 100644 index 0000000..e8e3ce2 --- /dev/null +++ b/coverage/project-code/src/db/model/ContributorGroup.ts.html @@ -0,0 +1,227 @@ + + + + Code coverage report for project-code/src/db/model/ContributorGroup.ts + + + + + + + +
+
+

+ All files / project-code/src/db/model ContributorGroup.ts +

+
+
+ 53.85% + Statements + 14/26 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/3 +
+
+ 86.67% + Lines + 13/15 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +551x +  +1x +  +  +1x +  +  +1x +  +  +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +  +1x +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { AllowNull, Column, DataType, HasMany, Model, Table
+	} from 'sequelize-typescript';
+import { default as UserJoinsProject } from './UserJoinsProject';
+ 
+@Table
+export default class ContributorGroup extends Model<ContributorGroup> {
+	@AllowNull
+	@Column(DataType.TEXT)
+	public name: string | null = null;
+ 
+	/* "Error: Foreign key for "ContributorGroup"
+	 * is missing on "UserJoinsProject"." */
+	@HasMany(() => UserJoinsProject, 'contributorGroupId')
+	public uses: UserJoinsProject[] = [];
+ 
+	@Column
+	public canCreateFiles: boolean = false;
+ 
+	@Column
+	public canDeleteFiles: boolean = false;
+ 
+	@Column
+	public canViewFiles: boolean = false;
+ 
+	@Column
+	public canAddUsers: boolean = false;
+ 
+	@Column
+	public canRemoveUsers: boolean = false;
+ 
+	@Column
+	public canEditUserPermissions: boolean = false;
+ 
+	@AllowNull
+	@Column(DataType.TEXT)
+	public description: string | null = null;
+ 
+	@Column
+	public isInternal: boolean = true;
+ 
+	public getContributorGroupFullInfo(): ContributorGroupFullInfo {
+		return {
+			role: `${this.name}`,
+			description: `${this.description}`,
+			internal: this.isInternal
+		};
+	}
+}
+ 
+export interface ContributorGroupFullInfo {
+	role: string;
+	description: string;
+	internal: boolean;
+}
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/File.ts.html b/coverage/project-code/src/db/model/File.ts.html new file mode 100644 index 0000000..f552af3 --- /dev/null +++ b/coverage/project-code/src/db/model/File.ts.html @@ -0,0 +1,206 @@ + + + + Code coverage report for project-code/src/db/model/File.ts + + + + + + + +
+
+

+ All files / project-code/src/db/model File.ts +

+
+
+ 48.48% + Statements + 16/33 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/7 +
+
+ 71.43% + Lines + 15/21 +
+
+
+
+

+
+
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 +481x +1x +  +1x +  +  +1x +  +1x +  +  +  +1x +  +  +1x +  +  +  +  +1x +  +  +1x +  +  +1x +  +  +  +  +1x +  +  +1x +  +  +1x +  +  +  +1x +  +  +  +1x +  + 
import { default as Project } from './Project';
+import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany,
+		HasOne, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript';
+import { default as User } from './User';
+ 
+@Table
+export default class File extends Model<File> {
+	@Column
+	public name: string = '';
+ 
+	@PrimaryKey
+	@Column
+	public uuid: string = '';
+ 
+	@Column
+	public mimetype: string = '';
+ 
+	@ForeignKey(() => File)
+	@AllowNull
+	@Column(DataType.TEXT)
+	public parentFolderId: string | null = null;
+ 
+	@BelongsTo(() => File)
+	public parentFolder: File = new File();
+ 
+	@HasMany(() => File)
+	public containedFiles: File[] = [];
+ 
+	@ForeignKey(() => User)
+	@AllowNull
+	@Column(DataType.TEXT)
+	public creatorName: string | null = null;
+ 
+	@BelongsTo(() => User)
+	public creator: User = new User();
+ 
+	@HasOne(() => Project)
+	public rootFolderOf: Project = new Project();
+ 
+	@CreatedAt
+	@Column
+	public uploadDate: Date = new Date();
+ 
+	@UpdatedAt
+	@Column
+	public modifyDate: Date = new Date();
+}
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/Project.ts.html b/coverage/project-code/src/db/model/Project.ts.html new file mode 100644 index 0000000..b6270dc --- /dev/null +++ b/coverage/project-code/src/db/model/Project.ts.html @@ -0,0 +1,290 @@ + + + + Code coverage report for project-code/src/db/model/Project.ts + + + + + + + +
+
+

+ All files / project-code/src/db/model Project.ts +

+
+
+ 46.15% + Statements + 12/26 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/9 +
+
+ 61.11% + Lines + 11/18 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76  +1x +1x +  +1x +1x +  +  +1x +  +  +  +1x +  +  +1x +  +  +  +1x +  +  +1x +  +  +  +1x +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { default as ContributorGroup } from './ContributorGroup';
+import { default as File } from './File';
+import { BelongsTo, BelongsToMany, Column, CreatedAt, ForeignKey,
+		Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript';
+import { default as User } from './User';
+import { default as UserJoinsProject } from './UserJoinsProject';
+ 
+@Table
+export default class Project extends Model<Project> {
+ 
+	@PrimaryKey
+	@Column
+	public name: string = '';
+ 
+	@BelongsToMany(() => User, () => UserJoinsProject)
+	public contributors: User[] = [];
+ 
+	@ForeignKey(() => File)
+	@Column
+	public rootFolderId: string = '';
+ 
+	@BelongsTo(() => File)
+	public rootFolder: File = new File();
+ 
+	@CreatedAt
+	@Column
+	public creationDate: Date = new Date();
+ 
+	@UpdatedAt
+	@Column
+	public lastActivity: Date = new Date();
+ 
+	public getAccessLevel(user: User): ContributorGroup {
+		throw new Error(`unimplemented, ${this}`);
+	}
+ 
+	public getUserInfo(user: User): UserInfo {
+		return {
+			username: user.username,
+			access_level: this.getAccessLevel(user)
+				.toString()
+		};
+	}
+ 
+	public getProjectFullInfo(): ProjectFullInfo {
+		return {
+			project_name: this.name,
+			users: this.contributors
+			.map<UserInfo>(
+				(u: User) => this.getUserInfo(u)
+			),
+			public_metadata: {
+				creation_date: this.creationDate
+			},
+			// TODO: Check if we have anything to use these for yet?
+			private_metadata: {},
+			admin_metadata: {}
+		};
+	}
+}
+ 
+interface Metadata {}
+ 
+interface UserInfo {
+	username: string;
+	access_level: string;
+}
+ 
+export interface ProjectFullInfo {
+	project_name: string;
+	users: UserInfo[];
+	public_metadata: Metadata;
+	private_metadata?: Metadata;
+	admin_metadata?: Metadata;
+}
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/User.ts.html b/coverage/project-code/src/db/model/User.ts.html new file mode 100644 index 0000000..ffec619 --- /dev/null +++ b/coverage/project-code/src/db/model/User.ts.html @@ -0,0 +1,299 @@ + + + + Code coverage report for project-code/src/db/model/User.ts + + + + + + + +
+
+

+ All files / project-code/src/db/model User.ts +

+
+
+ 46.67% + Statements + 14/30 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/10 +
+
+ 61.9% + Lines + 13/21 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +791x +1x +1x +  +1x +1x +  +  +1x +  +  +1x +  +  +1x +  +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
import { default as File } from './File';
+import { default as Project } from './Project';
+import { BelongsTo, BelongsToMany, Column, CreatedAt, ForeignKey, HasMany,
+		Model, PrimaryKey, Table } from 'sequelize-typescript';
+import { default as UserGroup } from './UserGroup';
+import { default as UserJoinsProject } from './UserJoinsProject';
+ 
+@Table
+export default class User extends Model<User> {
+	@PrimaryKey
+	@Column
+	public username: string = '';
+ 
+	@Column
+	public password: string = '';
+ 
+	@ForeignKey(() => UserGroup)
+	@Column
+	public userGroupId: number = 0;
+ 
+	@BelongsTo(() => UserGroup)
+	public userGroup: UserGroup = new UserGroup();
+ 
+	@BelongsToMany(() => Project, () => UserJoinsProject)
+	public projects: Project[] = [];
+ 
+	@HasMany(() => File)
+	public createdFiles: File[] = [];
+ 
+	@CreatedAt
+	@Column
+	public creationDate: Date = new Date();
+ 
+	// TODO implement
+	public getAccessLevel(project: Project): string {
+		throw new Error(`unimplemented, ${this}`);
+	}
+ 
+	public getProjectInfo(project: Project): ProjectInfo {
+		return {
+			project_name: project.name,
+			access_level: this.getAccessLevel(project)
+		};
+	}
+ 
+	public getUserFullInfo(): UserFullInfo {
+		return {
+			username : this.username,
+			privileges: [`${this.userGroup.name}`],
+			projects : this.projects.map<ProjectInfo>(
+				(p: Project) => this.getProjectInfo(p)
+			),
+			// TODO: Check if we have anything to use these for yet?
+			public_user_metadata: {},
+			private_user_metadata: {},
+			public_admin_metadata: {},
+			private_admin_metadata: {}
+		};
+	}
+}
+ 
+// TODO MAKE PRETTY below
+interface Metadata {}
+ 
+interface ProjectInfo {
+	project_name: string;
+	access_level: string;
+}
+ 
+export interface UserFullInfo {
+	username: string;
+	privileges: string[];
+	projects: ProjectInfo[];
+	public_user_metadata: Metadata;
+	private_user_metadata: Metadata;
+	public_admin_metadata: Metadata;
+	private_admin_metadata: Metadata;
+}
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/UserGroup.ts.html b/coverage/project-code/src/db/model/UserGroup.ts.html new file mode 100644 index 0000000..75f5fbf --- /dev/null +++ b/coverage/project-code/src/db/model/UserGroup.ts.html @@ -0,0 +1,221 @@ + + + + Code coverage report for project-code/src/db/model/UserGroup.ts + + + + + + + +
+
+

+ All files / project-code/src/db/model UserGroup.ts +

+
+
+ 53.85% + Statements + 14/26 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/3 +
+
+ 86.67% + Lines + 13/15 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +531x +  +1x +  +  +  +  +  +  +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +  +1x +  +  +  +  +  +  +  +  +  + 
import { AllowNull, Column, DataType, HasMany, Model, Table
+	} from 'sequelize-typescript';
+import { default as User } from './User';
+ 
+interface UserPrivilege {
+	privilege: string;
+	description: string;
+	internal: boolean;
+}
+ 
+@Table
+export default class UserGroup extends Model<UserGroup> {
+	@AllowNull
+	@Column(DataType.TEXT)
+	public name: string | null = null;
+ 
+	@HasMany(() => User)
+	public users: User[] = [];
+ 
+	@Column
+	public canCreateUsers: boolean = false;
+ 
+	@Column
+	public canDeleteUsers: boolean = false;
+ 
+	@Column
+	public canEditUsers: boolean = false;
+ 
+	@Column
+	public canCreateProjects: boolean = false;
+ 
+	@Column
+	public canDeleteProjects: boolean = false;
+ 
+	@Column
+	public canEditProjects: boolean = false;
+ 
+	@Column
+	public isInternal: boolean = true;
+ 
+	@AllowNull
+	@Column(DataType.TEXT)
+	public description: string | null = null;
+ 
+	public getPrivelege(): UserPrivilege {
+		return {
+			privilege : `${this.name}`,
+			description : `${this.description}`,
+			internal : this.isInternal
+		};
+	}
+}
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/UserJoinsProject.ts.html b/coverage/project-code/src/db/model/UserJoinsProject.ts.html new file mode 100644 index 0000000..0783bbd --- /dev/null +++ b/coverage/project-code/src/db/model/UserJoinsProject.ts.html @@ -0,0 +1,146 @@ + + + + Code coverage report for project-code/src/db/model/UserJoinsProject.ts + + + + + + + +
+
+

+ All files / project-code/src/db/model UserJoinsProject.ts +

+
+
+ 55% + Statements + 11/20 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/5 +
+
+ 71.43% + Lines + 10/14 +
+
+
+
+

+
+
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 +281x +1x +  +1x +1x +  +  +1x +  +  +1x +  +  +  +1x +  +  +  +1x +  +  +  +1x +  +  +1x +  + 
import { default as Project } from './Project';
+import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table
+	} from 'sequelize-typescript';
+import { default as User } from './User';
+import { default as ContributorGroup } from './UserGroup';
+ 
+@Table
+export default class UserJoinsProject extends Model<UserJoinsProject> {
+	@ForeignKey(() => User)
+	@Column
+	public username: string = '';
+ 
+	@ForeignKey(() => Project)
+	@Column
+	public projectName: string = '';
+ 
+	@CreatedAt
+	@Column
+	public joinDate: Date = new Date();
+ 
+	@ForeignKey(() => ContributorGroup)
+	@Column
+	public contributorGroupId: number = 0;
+ 
+	@BelongsTo(() => ContributorGroup)
+	public contributorGroup: ContributorGroup = new ContributorGroup();
+}
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/model/index.html b/coverage/project-code/src/db/model/index.html new file mode 100644 index 0000000..0a79060 --- /dev/null +++ b/coverage/project-code/src/db/model/index.html @@ -0,0 +1,158 @@ + + + + Code coverage report for project-code/src/db/model + + + + + + + +
+
+

+ All files project-code/src/db/model +

+
+
+ 50.31% + Statements + 81/161 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/37 +
+
+ 72.12% + Lines + 75/104 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
ContributorGroup.ts
53.85%14/26100%0/00%0/386.67%13/15
File.ts
48.48%16/33100%0/00%0/771.43%15/21
Project.ts
46.15%12/26100%0/00%0/961.11%11/18
User.ts
46.67%14/30100%0/00%0/1061.9%13/21
UserGroup.ts
53.85%14/26100%0/00%0/386.67%13/15
UserJoinsProject.ts
55%11/20100%0/00%0/571.43%10/14
+
+
+ + + + + + + diff --git a/coverage/project-code/src/db/orm.ts.html b/coverage/project-code/src/db/orm.ts.html new file mode 100644 index 0000000..e8b90ab --- /dev/null +++ b/coverage/project-code/src/db/orm.ts.html @@ -0,0 +1,101 @@ + + + + Code coverage report for project-code/src/db/orm.ts + + + + + + + +
+
+

+ All files / project-code/src/db orm.ts +

+
+
+ 0% + Statements + 0/1 +
+
+ 100% + Branches + 0/0 +
+
+ 100% + Functions + 0/0 +
+
+ 0% + Lines + 0/1 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13  +  +  +  +  +  +  +  +  +  +  +  + 
import { Sequelize } from 'sequelize-typescript';
+ 
+const seq: Sequelize = new Sequelize({
+  database: 'be4',
+  dialect: 'postgres',
+  username: 'admin',
+  password: '',
+  operatorsAliases: false,
+  modelPaths: [`${__dirname}/model`]
+});
+ 
+export default seq;
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/index.html b/coverage/project-code/src/index.html new file mode 100644 index 0000000..4307500 --- /dev/null +++ b/coverage/project-code/src/index.html @@ -0,0 +1,93 @@ + + + + Code coverage report for project-code/src + + + + + + + +
+
+

+ All files project-code/src +

+
+
+ 0% + Statements + 0/16 +
+
+ 0% + Branches + 0/4 +
+
+ 0% + Functions + 0/2 +
+
+ 0% + Lines + 0/16 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
index.ts
0%0/160%0/40%0/20%0/16
+
+
+ + + + + + + diff --git a/coverage/project-code/src/index.ts.html b/coverage/project-code/src/index.ts.html new file mode 100644 index 0000000..d4515b2 --- /dev/null +++ b/coverage/project-code/src/index.ts.html @@ -0,0 +1,227 @@ + + + + Code coverage report for project-code/src/index.ts + + + + + + + +
+
+

+ All files / project-code/src index.ts +

+
+
+ 0% + Statements + 0/16 +
+
+ 0% + Branches + 0/4 +
+
+ 0% + Functions + 0/2 +
+
+ 0% + Lines + 0/16 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
/* tslint:disable:no-console
+ * This only goes here until we have a logging system */
+ 
+console.log('begin import');
+import { default as app } from './app';
+import { default as seq } from './db/orm';
+console.log('end import');
+ 
+import { default as UserGroup } from './db/model/UserGroup';
+ 
+const DEFAULT_PORT: number = 3000;
+ 
+// Use default port 3000 or port supplied by OS
+const port: number = process.env.PORT
+	? process.env.PORT
+	: DEFAULT_PORT;
+ 
+// tslint:disable:no-floating-promises
+(async(): Promise<void> => {
+	console.log('Booting PSQL database');
+ 
+	await seq.authenticate();
+ 
+	console.log('Resetting Database');
+ 
+	await seq.sync({
+		force: true
+	});
+ 
+	const admin: UserGroup = new UserGroup({
+		name: 'admin',
+		canCreateUsers: true,
+		canDeleteUsers: true,
+		canEditUsers: true,
+		canCreateProjects: true,
+		canDeleteProjects: true,
+		canEditProjects: true,
+		isInternal: false,
+		description: 'Systems admin'
+	});
+ 
+	// tslint:disable:no-floating-promises
+	admin.save();
+ 
+	console.log('Booting ExpressJS server');
+ 
+	app.listen(port, (err: Error) => {
+		if (err) {
+			return console.log(err);
+		} else {
+			return console.log(`server is listening on port ${port}`);
+		}
+	});
+})();
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/matcher/index.html b/coverage/project-code/src/matcher/index.html new file mode 100644 index 0000000..502c1a9 --- /dev/null +++ b/coverage/project-code/src/matcher/index.html @@ -0,0 +1,106 @@ + + + + Code coverage report for project-code/src/matcher + + + + + + + +
+
+

+ All files project-code/src/matcher +

+
+
+ 0% + Statements + 0/169 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/79 +
+
+ 0% + Lines + 0/169 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
options.unit.test.ts
0%0/69100%0/00%0/290%0/69
types.unit.test.ts
0%0/100100%0/00%0/500%0/100
+
+
+ + + + + + + diff --git a/coverage/project-code/src/matcher/options.ts.html b/coverage/project-code/src/matcher/options.ts.html new file mode 100644 index 0000000..79d0f7e --- /dev/null +++ b/coverage/project-code/src/matcher/options.ts.html @@ -0,0 +1,362 @@ + + + + Code coverage report for project-code/src/matcher/options.ts + + + + + + + +
+
+

+ All files / project-code/src/matcher options.ts +

+
+
+ 63.04% + Statements + 29/46 +
+
+ 46.67% + Branches + 14/30 +
+
+ 77.78% + Functions + 7/9 +
+
+ 65.91% + Lines + 29/44 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +1001x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +35x +12x +23x +13x +10x +  +10x +10x +  +14x +14x +  +  +  +  +  +  +  +1x +22x +1x +  +21x +  +  +  +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +11x +11x +  +  +  +  +  +1x +3x +3x +  +  +  +  +  +  +  +  +  +1x +14x +14x +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +1x + 
import { Atom, default as types } from './types';
+ 
+type Checker = ((value: Value | undefined) => boolean);
+ 
+export type TemplateValue =
+	Atom | Template | Checker;
+ 
+export interface Template {
+	[key: string]: TemplateValue | undefined;
+}
+ 
+export type Value =
+	{ [key: string]: Value | undefined } | Atom;
+ 
+const matchNoCurry:
+	(template: TemplateValue, value: Value | undefined) => boolean =
+	(template: TemplateValue, value: Value | undefined): boolean => {
+	if (types.atom(template)) {
+		return template === value;
+	} else if (types.function(template)) {
+		return template(value);
+	} else Iif (types.atom(value) || value === undefined) {
+		return false;
+	} else Eif (types.object(template)) {
+		return Object.keys(template)
+			.every((key: string): boolean => {
+				const v: Value | undefined = value[key];
+				return matchNoCurry(template[key] as TemplateValue, v);
+			});
+	} else {
+		throw new Error(`Unknown template value: ${template}`);
+	}
+};
+ 
+// tslint:disable-next-line:typedef
+export const match = (template: TemplateValue, value?: Value) => {
+	if (value === undefined) {
+		return matchNoCurry.bind(null, template);
+	}
+	return matchNoCurry(template, value);
+};
+ 
+// tslint:disable-next-line:typedef
+export const exact = (template: Template, value?: Value) => {
+	Eif (value === undefined) {
+		return exact.bind(null, template);
+	}
+	if (!match(template, value)) {
+		return false;
+	}
+	if (!types.atom(value)) {
+		const k1: string[] = Object.keys(template);
+		const k2: string[] = Object.keys(value);
+		return k2.every((x: string) => k1.indexOf(x) < 0);
+	} else {
+		return true;
+	}
+};
+ 
+// tslint:disable-next-line:typedef
+export const optional = (template: TemplateValue, value?: Value) => {
+	Eif (value === undefined) {
+		return optional.bind(null, template);
+	}
+	return types.undefined(value) || match(template, value);
+};
+ 
+// tslint:disable-next-line:typedef
+export const alternative = (templates: TemplateValue[], value?: Value) => {
+	Eif (value === undefined) {
+		return alternative.bind(null, templates);
+	}
+	if (templates.length === 0) {
+		return false;
+	} else {
+		return templates.some((t: TemplateValue): boolean => match(t, value));
+	}
+};
+ 
+// tslint:disable-next-line:typedef
+export const array = (template: TemplateValue, values?: Value[]) => {
+	Eif (values === undefined) {
+		return array.bind(null, template);
+	}
+	const m: Checker = types.function(template)
+		? template
+		: match.bind(null, template);
+	return values.every(m);
+};
+ 
+// tslint:disable-next-line:typedef
+const options = {
+	match,
+	exact,
+	optional,
+	alternative,
+	array
+};
+export default options;
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/matcher/options.unit.test.ts.html b/coverage/project-code/src/matcher/options.unit.test.ts.html new file mode 100644 index 0000000..f629ef7 --- /dev/null +++ b/coverage/project-code/src/matcher/options.unit.test.ts.html @@ -0,0 +1,554 @@ + + + + Code coverage report for project-code/src/matcher/options.unit.test.ts + + + + + + + +
+
+

+ All files / project-code/src/matcher options.unit.test.ts +

+
+
+ 0% + Statements + 0/69 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/29 +
+
+ 0% + Lines + 0/69 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
/* tslint:disable:typedef */
+// Disabled to allow quick template creation.
+ 
+/* tslint:disable:newline-per-chained-call */
+// Disabled to allow Chai- and Mocha-style test formatting.
+ 
+/* tslint:disable:no-unused-expression */
+// Disabled to allow `...to.be.true`.
+ 
+import * as chai from 'chai';
+chai.should();
+ 
+import * as options from './options';
+import { default as types } from './types';
+ 
+// tslint:disable-next-line:no-require-imports
+ 
+describe('Matching:', () => {
+	describe('Rough Matching', () => {
+		context('for literals', () => {
+			context('accepts matching', () => {
+				it('strings', () => {
+					options.match('a', 'a').should.be.true;
+				});
+				it('numbers', () => {
+					options.match(3, 3).should.be.true;
+				});
+				it('boolean values', () => {
+					options.match(true, true).should.be.true;
+				});
+				it('null to null', () => {
+					options.match(null, null).should.be.true;
+				});
+			});
+			context('rejects', () => {
+				it('different strings', () => {
+					options.match('x', 'y').should.be.false;
+				});
+				it('different numbers', () => {
+					options.match(20, 42).should.be.false;
+				});
+				it('different boolean values', () => {
+					options.match(true, false).should.be.false;
+				});
+				it('different types', () => {
+					options.match('55', 55).should.be.false;
+				});
+				it('null matched with non-null values', () => {
+					options.match(null, false).should.be.false;
+				});
+				it('non-null values matched with null', () => {
+					options.match(0, null).should.be.false;
+				});
+			});
+		});
+		context('for checker functions', () => {
+			context('accepts', () => {
+				it('values that succeed the checker function', () => {
+					options.match(types.number, 9).should.be.true;
+				});
+			});
+			context('rejects', () => {
+				it('values that do not succeed the checker function', () => {
+					options.match(types.boolean, 'true').should.be.false;
+				});
+			});
+		});
+		it('accepts basic things', () => {
+			const template = {
+				a: types.string
+			};
+			const matchee = {
+				a: 'yes'
+			};
+			options.match(template, matchee).should.be.true;
+		});
+		it('accepts objects with superfluous properties', () => {
+			const template = {
+				a: types.number
+			};
+			const matchee = {
+				a: 40,
+				b: 20
+			};
+			options.match(template, matchee).should.be.true;
+		});
+		it('rejects objects missing some properties', () => {
+			const template = {
+				a: types.boolean,
+				b: types.number,
+				c: types.number
+			};
+			const matchee = {
+				b: 5
+			};
+			options.match(template, matchee).should.be.false;
+		});
+		it('accepts objects that omit not_present properties', () => {
+			const template = {
+				a: types.number,
+				b: types.not_present,
+				c: types.not_present
+			};
+			const matchee = {
+				a: 4
+			};
+			options.match(template, matchee).should.be.true;
+		});
+		it('rejects empty objects for non-empty templates', () => {
+			const template = {
+				a: types.boolean
+			};
+			const matchee = {
+			};
+			options.match(template, matchee).should.be.false;
+		});
+		it('accepts empty objects for empty templates', () => {
+			const template = {
+			};
+			const matchee = {
+			};
+			options.match(template, matchee).should.be.true;
+		});
+		it('accepts nested objects that match', () => {
+			const template = {
+				a: types.number,
+				b: {
+					ba: types.string,
+					bb: types.string
+				},
+				c: types.boolean
+			};
+			const matchee = {
+				a: 432,
+				b: {
+					ba: 'baracus',
+					bb: 'ATEAM'
+				},
+				c: true,
+				x: false
+			};
+			options.match(template, matchee).should.be.true;
+		});
+		it('accepts literal matches', () => {
+			const template = {
+				a: 'literal'
+			};
+			const matchee = {
+				a: 'literal'
+			};
+			options.match(template, matchee).should.be.true;
+		});
+		it('rejects incorrect literal matches', () => {
+			const template = {
+				g: 99
+			};
+			const matchee = {
+				g: 80
+			};
+			options.match(template, matchee).should.be.false;
+		});
+	});
+});
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/matcher/types.ts.html b/coverage/project-code/src/matcher/types.ts.html new file mode 100644 index 0000000..cbe10a0 --- /dev/null +++ b/coverage/project-code/src/matcher/types.ts.html @@ -0,0 +1,302 @@ + + + + Code coverage report for project-code/src/matcher/types.ts + + + + + + + +
+
+

+ All files / project-code/src/matcher types.ts +

+
+
+ 100% + Statements + 22/22 +
+
+ 100% + Branches + 8/8 +
+
+ 100% + Functions + 7/7 +
+
+ 100% + Lines + 22/22 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80  +  +  +  +  +  +  +1x +6x +213x +6x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +45x +  +1x +9x +  +1x +6x +  +1x +5x +  +1x +  +45x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x + 
/* tslint:disable:no-any */
+ 
+type Checker<T = any> = (v: any) => v is T;
+ 
+export type Atom = Number | String | Boolean | null;
+ 
+const typeCheckerGenerator: <T>(test: T) => Checker<T> =
+	<T>(test: T): Checker<T> => {
+	const f: Checker<T> = (value: any): value is T =>
+		value != null && value.constructor === test.constructor;
+	return f;
+};
+ 
+export const isObject: Checker<Object> =
+	typeCheckerGenerator<Object>({});
+ 
+export const isNumber: Checker<Number> =
+	typeCheckerGenerator<Number>(0);
+ 
+export const isString: Checker<String> =
+	typeCheckerGenerator<String>('');
+ 
+export const isBoolean: Checker<Boolean> =
+	typeCheckerGenerator<Boolean>(true);
+ 
+export const isArray: Checker<any[]> =
+	typeCheckerGenerator<any[]>([]);
+ 
+export const isFunction: Checker<Function> =
+	typeCheckerGenerator<Function>(new Function());
+ 
+export const isNull: Checker<null> =
+	(v: any): v is null => v === null;
+ 
+export const isUndefined: Checker<undefined> =
+	(v: any): v is undefined => v === undefined;
+ 
+export const isPresent: (v: any) => boolean =
+	(v: any): boolean => !isUndefined(v);
+ 
+export const isInteger: Checker<Number> =
+	(v: any): v is Number => isNumber(v) && Number.isInteger(v as number);
+ 
+export const isAtom: Checker<Atom> =
+	(v: any): v is Atom =>
+		isNull(v) || isNumber(v) || isString(v) || isBoolean(v);
+ 
+const types: {
+	object: Checker<Object>;
+	number: Checker<Number>;
+	string: Checker<String>;
+	boolean: Checker<Boolean>;
+	array: Checker<any[]>;
+	function: Checker<Function>;
+	integer: Checker<Number>;
+	null: Checker<null>;
+	present: (v: any) => boolean;
+	is_present: (v: any) => boolean;
+	not_present: Checker<undefined>;
+	undefined: Checker<undefined>;
+	anything: (v: any) => boolean;
+	atom: Checker<Atom>;
+} = {
+	object:      isObject,
+	number:      isNumber,
+	string:      isString,
+	boolean:     isBoolean,
+	array:       isArray,
+	function:    isFunction,
+	integer:     isInteger,
+	null:        isNull,
+	present:     isPresent,
+	is_present:  isPresent,
+	not_present: isUndefined,
+	undefined:   isUndefined,
+	anything:    isPresent,
+	atom:        isAtom
+};
+export default types;
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/matcher/types.unit.test.ts.html b/coverage/project-code/src/matcher/types.unit.test.ts.html new file mode 100644 index 0000000..4c4ac53 --- /dev/null +++ b/coverage/project-code/src/matcher/types.unit.test.ts.html @@ -0,0 +1,599 @@ + + + + Code coverage report for project-code/src/matcher/types.unit.test.ts + + + + + + + +
+
+

+ All files / project-code/src/matcher types.unit.test.ts +

+
+
+ 0% + Statements + 0/100 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/50 +
+
+ 0% + Lines + 0/100 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
/* tslint:disable:no-unused-expression */
+// Disabled to allow `...to.be.true`.
+ 
+import * as chai from 'chai';
+chai.should();
+ 
+import { default as types } from './types';
+ 
+describe('Type Checking:', () => {
+  for (const x of [
+	{ name: 'Object',  func: types.object  },
+	{ name: 'Number',  func: types.number  },
+	{ name: 'Integer', func: types.integer },
+	{ name: 'String',  func: types.string  },
+	{ name: 'Boolean', func: types.boolean },
+	{ name: 'Array',   func: types.array   }
+  ]) {
+	describe(`${x.name} Checking`, () => {
+  	it('rejects null', () => {
+		x.func(null).should.be.false;
+		});
+		 it('rejects undefined', () => {
+		x.func(undefined).should.be.false;
+		});
+	});
+  }
+ 
+  describe('Presence Checking', () => {
+	it('accepts non-undefined values', () => {
+		types.anything(1).should.be.true;
+		types.anything('string').should.be.true;
+		types.anything(false).should.be.true;
+	});
+	it('accepts null', () => {
+		types.anything(null).should.be.true;
+	});
+	it('rejects undefined', () => {
+		types.anything(undefined).should.be.false;
+	});
+	it('rejects objects without the named property', () => {
+		const x: { [key: string]: number } = {};
+		/* There's no way to pick a key that definitely won't be
+		/* on the object */
+		types.anything(x["hopefully this isn't a property"])
+		.should.be.false;
+	});
+  });
+ 
+  describe('Absence Checking', () => {
+	it('accepts undefined', () => {
+		types.not_present(undefined).should.be.true;
+	});
+  });
+ 
+  describe('Number Checking', () => {
+	it('accepts positive integers', () => {
+		types.number(4).should.be.true;
+	});
+	it('accepts negative integers', () => {
+		types.number(-10).should.be.true;
+	});
+	it('accepts floats', () => {
+		types.number(3.14).should.be.true;
+	});
+	it('accepts zero', () => {
+		types.number(0).should.be.true;
+	});
+	it('accepts boxed numbers', () => {
+		// tslint:disable-next-line:no-construct
+		types.number(new Number(20)).should.be.true;
+	});
+	it('rejects strings', () => {
+		types.number('haha').should.be.false;
+	});
+	it('rejects objects', () => {
+		types.number(new Object()).should.be.false;
+	});
+	it('rejects arrays', () => {
+		types.number([1, 2, 3]).should.be.false;
+	});
+	it('rejects things that look like numbers', () => {
+		types.number('1234').should.be.false;
+		types.number('-3.14').should.be.false;
+	});
+	it('accepts NaN', () => {
+		types.number(NaN).should.be.true;
+	});
+	it('accepts Infinity', () => {
+		types.number(Infinity).should.be.true;
+	});
+  });
+ 
+  describe('Integer Checking', () => {
+	it('rejects non-integer numbers', () => {
+		types.integer(3.14).should.be.false;
+	});
+	it('rejects NaN', () => {
+		types.integer(NaN).should.be.false;
+	});
+	it('rejects Infinity', () => {
+		types.integer(Infinity).should.be.false;
+	});
+  });
+ 
+  describe('String Checking', () => {
+	it('accepts basic primitive strings', () => {
+		types.string('string!').should.be.true;
+	});
+	it('accepts strings of numbers', () => {
+		types.string('1234').should.be.true;
+	});
+	it('accepts the empty string', () => {
+		types.string('').should.be.true;
+	});
+	it('accepts non-primitive string objects', () => {
+		// tslint:disable-next-line:no-construct
+		types.string(new String('String!')).should.be.true;
+	});
+	it('rejects numbers', () => {
+		types.string(5).should.be.false;
+		// tslint:disable-next-line:no-construct
+		types.string(new Number(28)).should.be.false;
+	});
+	it('rejects objects', () => {
+		types.string(new Object()).should.be.false;
+	});
+	it('rejects arrays', () => {
+		types.string(['ah', 'ha']).should.be.false;
+	});
+  });
+ 
+  describe('Boolean Checking', () => {
+	it('accepts true and false', () => {
+		types.boolean(true).should.be.true;
+		types.boolean(false).should.be.true;
+	});
+	it('rejects numbers', () => {
+		types.boolean(2).should.be.false;
+	});
+	it('rejects strings', () => {
+		types.boolean('not boolean').should.be.false;
+	});
+	it('rejects strings of boolean values', () => {
+		types.boolean('true').should.be.false;
+	});
+	it('rejects objects', () => {
+		types.boolean(new Object()).should.be.false;
+	});
+	it('rejects arrays', () => {
+		types.boolean([true, true, false]).should.be.false;
+	});
+	it('rejects falsy values', () => {
+		types.boolean(0).should.be.false;
+	});
+  });
+ 
+  describe('Array Checking', () => {
+	it('accepts arrays', () => {
+		types.array([1, 'two', false]).should.be.true;
+	});
+	it('accepts empty arrays', () => {
+		types.array([]).should.be.true;
+		types.array(new Array()).should.be.true;
+	});
+	it('rejects strings', () => {
+		types.array('not an array').should.be.false;
+	});
+	it('rejects strings that look like arrays', () => {
+		types.array('[1, 2, false]').should.be.false;
+	});
+	it('rejects numbers', () => {
+		types.array(8).should.be.false;
+	});
+	it('rejects objects', () => {
+		types.array(new Object()).should.be.false;
+	});
+  });
+});
+ 
+
+
+ + + + + + + diff --git a/coverage/project-code/src/serverConfig.ts.html b/coverage/project-code/src/serverConfig.ts.html new file mode 100644 index 0000000..16b59f6 --- /dev/null +++ b/coverage/project-code/src/serverConfig.ts.html @@ -0,0 +1,473 @@ + + + + Code coverage report for project-code/src/serverConfig.ts + + + + + + + +
+
+

+ All files / project-code/src serverConfig.ts +

+
+
+ 66.67% + Statements + 12/18 +
+
+ 0% + Branches + 0/2 +
+
+ 50% + Functions + 1/2 +
+
+ 66.67% + Lines + 12/18 +
+
+
+
+

+
+
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 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +1371x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +2x +2x +2x +2x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +1x + 
const serverConfig: Property[] = [];
+ 
+/**
+ * A way to display user-configurable properties.
+ */
+class PropertyDisplay {
+	/**
+	 * The category the property belongs to.
+	 */
+	public category: string;
+ 
+	/**
+	 * The group the property belongs to.
+	 */
+	public group: string;
+ 
+	/**
+	 * The name for the property to display to a user.
+	 */
+	public displayName: string;
+ 
+	/**
+	 * The description of the property.
+	 */
+	public description: string;
+ 
+	/**
+	 * Constructs a [[PropertyDisplay]] using its properties.
+	 *
+	 * @param cat	The property's category.
+	 * @param grp	The property's group.
+	 * @param dn	 The property's displayable name.
+	 * @param desc A description of the property.
+	 */
+	public constructor(cat: string, grp: string, dn: string, desc: string) {
+		this.category = cat;
+		this.group = grp;
+		this.displayName = dn;
+		this.description = desc;
+	}
+}
+ 
+/**
+ * A server property that infuences the running of the server.
+ * Loaded from configs at launch, and possibly editable during run-time.
+ */
+export interface Property {
+	/**
+	 * The property's unique ID.
+	 */
+	id: string;
+ 
+	/**
+	 * How to display the property to the user.
+	 */
+	display?: PropertyDisplay;
+ 
+	/**
+	 * Is the property read-only, or can it be edited at run-time?
+	 */
+	readOnly: boolean;
+ 
+	/**
+	 * The variable type of the property.
+	 *
+	 * These strings represent Javascript types directly,
+	 * except `"integer"`, which is a `number` in logic.
+	 */
+	type: 'string' | 'number' | 'integer' | 'boolean';
+ 
+	/**
+	 * The value of the property.
+	 */
+	value: string | number | boolean;
+}
+ 
+// Logging
+let propertyDisplay: PropertyDisplay = new PropertyDisplay(
+	'Logging',
+	'BE4',
+	'Is logging enabled?',
+	'This property defines if logging is currently enabled on this backend server.'
+);
+ 
+serverConfig.push({
+	id: 'Server_Log',
+	display: propertyDisplay,
+	readOnly: false,
+	type: 'boolean',
+	value: false
+});
+ 
+// Caching Settings (global)
+serverConfig.push({
+	id: 'Global_Cache_Limit',
+	readOnly: true,
+	type: 'integer',
+	value: 1
+});
+ 
+// Caching Settings (project level)
+propertyDisplay = new PropertyDisplay(
+	'Caching',
+	'BE4',
+	'Caching Type',
+	'This property defines the current caching style for this project.'
+);
+ 
+serverConfig.push({
+	id: 'project_example',
+	display: propertyDisplay,
+	readOnly: false,
+	type: 'integer',
+	value: 1
+});
+ 
+/**
+ * Checks if a property exists in the server's property list.
+ *
+ * @param propKey The property unique ID to search for.
+ * @returns The index of the property in the server's property list,
+ * or `-1` if the property is not present.
+ */
+export const propertyExists: (propKey: string) => number =
+	(propKey: string): number => {
+	let found: number = -1;
+	for (const prop in serverConfig) {
+		if (serverConfig[prop].id === propKey) {
+			found = parseInt(prop, 10);
+			break;
+		}
+	}
+	return found;
+};
+ 
+export default serverConfig;
+ 
+
+
+ + + + + + + -- cgit v1.2.1