-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update readme * Update eslint package to fix warning message * Add exit survey pacakge * exit survey * Use survey_function to format survey text * edit exit survey question titles and descriptions * change question names and MC values to match EFP names * add withdrawal and feedback questions * Change package name, exit survey parameters * Fixed typing * Added privacy and databrary params * Update API to get a study * Get study to add to withdraw copu * Add MD link * disable the video sharing questions if video withdrawal is true * add support for private level only option for media use question * fix private_level_only so that value is private in data * Add global data store * fix withdrawal question value in data and logic for enabling/disabling the other video-related questions * add validation for child birthdate: cannot be a future date * Combine helpers and api into new package called data * Update root package * Update initjspych to use new data structure * Update survey to use new data structure * Moved exit survey function to utils * First pass at tests * Add consent servey plugin * These packages are needed when building in linux environment * Add data finish function * Remove unneeded comments * Added text markdown to consent survey * Update tests * Update versions of deps * Update to getUuids * freeze loaded data * install jspsych/plugin-survey from npm and fix compatibility (pass object instead of JSON string) * replace exit.json with exit_json.ts and fix import * fix linting errors * fix failing data test due to syntax error in untranspiled deep-freeze node module * fix linting error * Needed to adjust ts config to build. --------- Co-authored-by: Becky Gilbert <[email protected]>
- Loading branch information
1 parent
82e56d2
commit cbf6ae7
Showing
46 changed files
with
2,198 additions
and
1,381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"jsonRecursiveSort": true, | ||
"plugins": [ | ||
"prettier-plugin-packagejson", | ||
"prettier-plugin-sort-json", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const config = require("@jspsych/config/jest").makePackageConfig(__dirname); | ||
module.exports = { | ||
...config, | ||
moduleNameMapper: {}, | ||
transformIgnorePatterns: ["node_modules/(?!deep-freeze-es6)"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "@lookit/lookit-api", | ||
"name": "@lookit/data", | ||
"version": "0.0.1", | ||
"description": "This is a JS implementation of lookit's RESTful API.", | ||
"homepage": "https://github.com/lookit/lookit-jspsych#readme", | ||
|
@@ -9,7 +9,7 @@ | |
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/lookit/lookit-jspsych.git", | ||
"directory": "packages/lookit-api" | ||
"directory": "packages/data" | ||
}, | ||
"license": "ISC", | ||
"author": "Christopher J Green <[email protected]> (https://github.com/okaycj)", | ||
|
@@ -20,9 +20,12 @@ | |
"dev": "rollup --config rollup.config.dev.mjs --watch", | ||
"test": "jest --coverage" | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"deep-freeze-es6": "^3.0.2" | ||
}, | ||
"devDependencies": { | ||
"@jspsych/config": "^2.0.0" | ||
"@jspsych/config": "^2.0.0", | ||
"jest-fetch-mock": "^3.0.3" | ||
}, | ||
"peerDependencies": { | ||
"jspsych": "^7.3.4" | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
packages/lookit-api/rollup.config.mjs → packages/data/rollup.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { makeRollupConfig } from "@jspsych/config/rollup"; | ||
|
||
export default makeRollupConfig("lookitAPI"); | ||
export default makeRollupConfig("chsData"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
finish, | ||
retrieveChild, | ||
retrievePastSessions, | ||
retrieveResponse, | ||
retrieveStudy, | ||
updateResponse, | ||
} from "./api"; | ||
|
||
jest.mock("./utils", () => ({ | ||
...jest.requireActual("./utils"), | ||
getUuids: jest.fn(), | ||
get: jest.fn().mockReturnValue("get response"), | ||
patch: jest.fn().mockReturnValue("patch response"), | ||
})); | ||
|
||
test("Api call to get Child", async () => { | ||
expect(await retrieveChild()).toStrictEqual("get response"); | ||
}); | ||
|
||
test("Api call to get Past Sessions", async () => { | ||
expect(await retrievePastSessions("some uuid")).toStrictEqual("get response"); | ||
}); | ||
|
||
test("Api call to get Study", async () => { | ||
expect(await retrieveStudy()).toStrictEqual("get response"); | ||
}); | ||
|
||
test("Api call to get Response", async () => { | ||
expect(await retrieveResponse("some uuid")).toStrictEqual("get response"); | ||
}); | ||
|
||
test("Api call to patch Response", async () => { | ||
expect(await updateResponse("some uuid", {})).toStrictEqual("patch response"); | ||
}); | ||
|
||
test("Check that all calls to API have finished", async () => { | ||
expect(await finish()).toStrictEqual([ | ||
"get response", | ||
"get response", | ||
"get response", | ||
"get response", | ||
"patch response", | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
Child, | ||
PastSession, | ||
Promises, | ||
Response, | ||
ResponseAttrsUpdate, | ||
ResponseUpdate, | ||
Study, | ||
} from "./types"; | ||
import { get, getUuids, patch } from "./utils"; | ||
|
||
const CONFIG = <const>{ ...getUuids() }; | ||
const promises: Promises[] = []; | ||
|
||
function deposit<T extends Promises>(promise: T) { | ||
promises.push(promise); | ||
return promise; | ||
} | ||
|
||
export function finish() { | ||
return Promise.all(promises); | ||
} | ||
|
||
export function retrieveChild() { | ||
return deposit(get<Child>(`children/${CONFIG.child}/`)); | ||
} | ||
|
||
export function retrievePastSessions(uuid: string) { | ||
return deposit(get<PastSession[]>(`past-sessions/${uuid}/`)); | ||
} | ||
|
||
export function retrieveStudy() { | ||
return deposit(get<Study>(`studies/${CONFIG.study}/`)); | ||
} | ||
|
||
export function retrieveResponse(uuid: string) { | ||
return deposit(get<Response>(`responses/${uuid}/`)); | ||
} | ||
|
||
export function updateResponse(uuid: string, data: ResponseAttrsUpdate) { | ||
return deposit( | ||
patch<ResponseUpdate, Response>(`responses/${uuid}/`, { | ||
id: uuid, | ||
type: "responses", | ||
attributes: data, | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Api from "./index"; | ||
|
||
jest.mock("./utils", () => ({ | ||
...jest.requireActual("./utils"), | ||
getUuids: jest.fn(), | ||
})); | ||
|
||
jest.mock("./api", () => ({ | ||
...jest.requireActual("./api"), | ||
retrieveStudy: jest.fn().mockReturnValue("Study"), | ||
retrieveChild: jest.fn().mockReturnValue("Child"), | ||
retrievePastSessions: jest.fn().mockReturnValue("PastSessions"), | ||
retrieveResponse: jest.fn().mockReturnValue("Response"), | ||
})); | ||
|
||
test("Load data for this study into window.chs", async () => { | ||
expect(Object.hasOwn(window, "chs")).toBeFalsy(); | ||
await Api.load("response uuid"); | ||
expect(window.chs).toEqual({ | ||
study: "Study", | ||
child: "Child", | ||
pastSessions: "PastSessions", | ||
response: "Response", | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import deepFreeze from "deep-freeze-es6"; | ||
import { | ||
finish, | ||
retrieveChild, | ||
retrievePastSessions, | ||
retrieveResponse, | ||
retrieveStudy, | ||
updateResponse, | ||
} from "./api"; | ||
import { Child, PastSession, Response, Study } from "./types"; | ||
|
||
declare global { | ||
interface Window { | ||
chs: { | ||
study: Study; | ||
child: Child; | ||
pastSessions: PastSession[]; | ||
response: Response; | ||
}; | ||
} | ||
} | ||
|
||
async function load(response_uuid: string) { | ||
if (!window.chs) { | ||
Object.assign(window, { | ||
chs: { | ||
study: await retrieveStudy(), | ||
child: await retrieveChild(), | ||
pastSessions: await retrievePastSessions(response_uuid), | ||
response: await retrieveResponse(response_uuid), | ||
}, | ||
}); | ||
deepFreeze(window.chs); | ||
} | ||
} | ||
|
||
export default { load, retrieveResponse, updateResponse, finish }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.