Skip to content

Commit

Permalink
tests compiling but no output
Browse files Browse the repository at this point in the history
  • Loading branch information
mizzao committed Nov 9, 2019
1 parent 36d0ed5 commit 740e3a1
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 56 deletions.
28 changes: 14 additions & 14 deletions lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* DS208: Avoid top-level this
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import { Meteor } from "meteor/meteor";
import { Mongo } from "meteor/mongo";
import { Tracker } from "meteor/tracker";

import { Partitioner } from "meteor/mizzao:partitioner";

export interface Batch {
_id: string;
active: boolean;
Expand Down Expand Up @@ -78,20 +78,25 @@ export type InstanceData = {
id: string;
joinTime: Date;
lastDisconnect?: Date;
disconnectedTime?: number;
lastIdle?: Date;
idleTime?: number;
};

export interface IAssignment {
_id: string;
batchId: string;
experimentId?: string;
hitId: string;
workerId: string;
assignmentId: string;
instances: InstanceData[];
treatments: string[];
mturkStatus: MTurkStatus;
status: "assigned" | "completed" | "returned";
bonusPaid: Date;
bonusPayment: number;
acceptTime?: Date;
instances?: InstanceData[];
treatments?: string[];
mturkStatus?: MTurkStatus;
status?: "assigned" | "completed" | "returned";
bonusPaid?: Date;
bonusPayment?: number;
}
export const Assignments = new Mongo.Collection<IAssignment>("ts.assignments");

Expand Down Expand Up @@ -164,8 +169,7 @@ Meteor.methods({

// Check if a particular user is an admin.
// If no user is specified, attempts to check the current user.
export function isAdmin(userId?: string): boolean {
userId = userId || Meteor.userId();
export function isAdmin(userId = Meteor.userId()): boolean {
if (userId == null) return false;

const user = Meteor.users.findOne(
Expand Down Expand Up @@ -233,7 +237,3 @@ TurkServer.partitionCollection(RoundTimers, {
name: "_groupId_1_index_1_unique"
}
});

function __guard__(value, transform) {
return typeof value !== "undefined" && value !== null ? transform(value) : undefined;
}
18 changes: 9 additions & 9 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ Package.onTest(function(api) {

api.addFiles("tests/display_fix.css");

api.addFiles("tests/utils.js"); // Deletes users so do it before insecure login
api.addFiles("tests/insecure_login.js");

api.addFiles("tests/lobby_tests.js");
api.addFiles("tests/admin_tests.js", "server");
api.addFiles("tests/auth_tests.js", "server");
api.addFiles("tests/connection_tests.js", "server");
api.addFiles("tests/experiment_tests.js", "server");
api.addFiles("tests/utils.ts"); // Deletes users so do it before insecure login
api.addFiles("tests/insecure_login.ts");

api.addFiles("tests/lobby_tests.ts");
api.addFiles("tests/admin_tests.ts", "server");
api.addFiles("tests/auth_tests.ts", "server");
api.addFiles("tests/connection_tests.ts", "server");
api.addFiles("tests/experiment_tests.ts", "server");
api.addFiles("tests/experiment_client_tests.js");
api.addFiles("tests/timer_tests.js", "server");
api.addFiles("tests/timer_tests.ts", "server");
api.addFiles("tests/logging_tests.js");
// This goes after experiment tests, so we can be sure that assigning works
api.addFiles("tests/assigner_tests.js", "server");
Expand Down
2 changes: 2 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { startup } from "./turkserver";
import { onConnect, onDisconnect, onIdle, onActive, connCallbacks } from "./connections";
import { scheduleOutstandingRounds, clearRoundHandlers } from "./timers_server";
import { authenticateWorker } from "./accounts_mturk";
import { treatment } from "./server_api";

import { formatMillis, _mergeTreatments } from "../lib/util";

Expand All @@ -29,6 +30,7 @@ export default {
formatMillis,
initialize,
startup,
treatment,
_mergeTreatments
};

Expand Down
5 changes: 4 additions & 1 deletion server/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Meteor } from "meteor/meteor";
import { check } from "meteor/check";

import { Partitioner } from "meteor/mizzao:partitioner";

import { Experiments, Treatments } from "../lib/common";
import { Assignment } from "./assignment";
import { Batch } from "./batches";
Expand Down Expand Up @@ -151,7 +153,8 @@ export class Instance {
* @returns {Array} the list of userIds
*/
users() {
return Experiments.findOne(this.groupId).users || [];
const instance = Experiments.findOne(this.groupId);
return (instance && instance.users) || [];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions server/timers_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const ROUND_END_NEWROUND = "newstart";
*/
export class Timers {
// TODO: export the above properly or something.
ROUND_END_TIMEOUT = ROUND_END_TIMEOUT;
ROUND_END_MANUAL = ROUND_END_MANUAL;
ROUND_END_NEWROUND = ROUND_END_NEWROUND;
static ROUND_END_TIMEOUT = ROUND_END_TIMEOUT;
static ROUND_END_MANUAL = ROUND_END_MANUAL;
static ROUND_END_NEWROUND = ROUND_END_NEWROUND;

/**
* @summary Starts a new round in the current instance.
Expand Down
14 changes: 12 additions & 2 deletions tests/admin_tests.js → tests/admin_tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { Meteor } from "meteor/meteor";
import { Random } from "meteor/random";
import { Tinytest } from "meteor/tinytest";

import { Batches, HITTypes, HITs, WorkerEmails, Workers } from "../lib/common";

import TurkServer, { TestUtils } from "../server";
import { assignQualification } from "../server/mturk";

// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
Expand All @@ -14,6 +23,7 @@ Batches.upsert({ _id: batchId }, { _id: batchId });
HITTypes.upsert({ HITTypeId: hitTypeId }, { $set: { batchId } });

// Temporarily disable the admin check during these tests
// TODO This won't work, so instead just make admin = true during tests.
const _checkAdmin = TurkServer.checkAdmin;

const withCleanup = TestUtils.getCleanupWrapper({
Expand Down Expand Up @@ -185,7 +195,7 @@ Tinytest.add(
return test.equal(params.SendNotification, false);
};

TurkServer.Util.assignQualification(workerId, qual, value, false);
assignQualification(workerId, qual, value, false);

// Check that worker has been updated
const worker = Workers.findOne(workerId);
Expand Down Expand Up @@ -216,7 +226,7 @@ Tinytest.add(
return test.equal(params.IntegerValue, value);
};

TurkServer.Util.assignQualification(workerId, qual, value, false);
assignQualification(workerId, qual, value, false);

// Check that worker has been updated
const worker = Workers.findOne(workerId);
Expand Down
15 changes: 11 additions & 4 deletions tests/auth_tests.js → tests/auth_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import { Meteor } from "meteor/meteor";
import { Tinytest } from "meteor/tinytest";

import TurkServer, { TestUtils } from "../server";
import { Batches, HITTypes, HITs, Assignments, ErrMsg } from "../lib/common";
import { authenticateWorker } from "../server/accounts_mturk";

const hitType = "authHitType";

const hitId = "authHitId";
Expand Down Expand Up @@ -62,7 +69,7 @@ const withCleanup = TestUtils.getCleanupWrapper({
Tinytest.add(
"auth - with first time hit assignment",
withCleanup(function(test) {
const asst = TestUtils.authenticateWorker({
const asst = authenticateWorker({
batchId: authBatchId,
hitId,
assignmentId,
Expand Down Expand Up @@ -92,7 +99,7 @@ Tinytest.add(
"auth - reject incorrect batch",
withCleanup(function(test) {
const testFunc = () =>
TestUtils.authenticateWorker({
authenticateWorker({
batchId: otherBatchId,
hitId,
assignmentId,
Expand All @@ -110,7 +117,7 @@ Tinytest.add(
Batches.update(authBatchId, { $unset: { active: false } });

const testFunc = () =>
TestUtils.authenticateWorker({
authenticateWorker({
batchId: authBatchId,
hitId,
assignmentId,
Expand All @@ -133,7 +140,7 @@ Tinytest.add(
});

// This needs to return an assignment
const asst = TestUtils.authenticateWorker({
const asst = authenticateWorker({
batchId: authBatchId,
hitId,
assignmentId,
Expand Down
11 changes: 10 additions & 1 deletion tests/connection_tests.js → tests/connection_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import { Meteor } from "meteor/meteor";
import { Tinytest } from "meteor/tinytest";

import { Partitioner } from "meteor/mizzao:partitioner";

import TurkServer, { TestUtils } from "../server";
import { Batches, Assignments, ErrMsg } from "../lib/common";
import { Assignment } from "../server/assignment";

const batchId = "connectionBatch";

Batches.upsert({ _id: batchId }, { _id: batchId });
Expand All @@ -20,7 +29,7 @@ const userId = "connectionUserId";

Meteor.users.upsert(userId, { $set: { workerId } });

let asst = null;
let asst: Assignment = null;

const instanceId = "connectionInstance";
const instance = batch.createInstance();
Expand Down
14 changes: 13 additions & 1 deletion tests/experiment_tests.js → tests/experiment_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const Doobie = new Mongo.Collection("experiment_test");

import { Meteor } from "meteor/meteor";
import { Mongo } from "meteor/mongo";
import { Accounts } from "meteor/accounts-base";
import { Random } from "meteor/random";
import { Tinytest } from "meteor/tinytest";

import { Partitioner } from "meteor/mizzao:partitioner";

import TurkServer, { TestUtils } from "../server";
import { Batches, Assignments, Experiments, Logs } from "../lib/common";

const Doobie = new Mongo.Collection<any>("experiment_test");

Partitioner.partitionCollection(Doobie);

Expand Down
11 changes: 9 additions & 2 deletions tests/insecure_login.js → tests/insecure_login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
InsecureLogin = {
import * as _ from "underscore";

import { Meteor } from "meteor/meteor";
import { Accounts } from "meteor/accounts-base";

import { Batches } from "../lib/common";

export const InsecureLogin = {
queue: [],
ran: false,
ready: function(callback) {
ready: function(callback: Function) {
this.queue.push(callback);
if (this.ran) this.unwind();
},
Expand Down
6 changes: 6 additions & 0 deletions tests/lobby_tests.js → tests/lobby_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
* DS103: Rewrite code to no longer use __guard__
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import { Meteor } from "meteor/meteor";
import { Tinytest } from "meteor/tinytest";

import { Batches, Assignments, LobbyStatus } from "../lib/common";
import TurkServer, { TestUtils } from "../server";

if (Meteor.isServer) {
// Create a batch to test the lobby on
const batchId = "lobbyBatchTest";
Expand Down
Loading

0 comments on commit 740e3a1

Please sign in to comment.