-
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.
* Remove unneeded package * Add lookit-api package * Add functions to get child and past sessions data * Add lookit helpers package * Expose child and past sessions data * Updated helper to be called by researchers * Add tests for coverage * Add text to tests * Update readme to address inter-package linking * Update to helper package config * changeset
- Loading branch information
Showing
22 changed files
with
653 additions
and
351 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@lookit/lookit-initjspsych": patch | ||
--- | ||
|
||
Update to package config |
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,5 @@ | ||
--- | ||
"@lookit/lookit-helpers": patch | ||
--- | ||
|
||
Initial deploy |
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,3 @@ | ||
const config = require("@jspsych/config/jest").makePackageConfig(__dirname); | ||
config.moduleNameMapper = {}; | ||
module.exports = config; |
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,15 @@ | ||
{ | ||
"name": "@lookit/lookit-api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "jest --coverage", | ||
"build": "rollup --config" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@jspsych/config": "^2.0.0" | ||
} | ||
} |
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,3 @@ | ||
import { makeRollupConfig } from "@jspsych/config/rollup"; | ||
|
||
export default makeRollupConfig("lookitAPI"); |
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,30 @@ | ||
import { enableFetchMocks } from "jest-fetch-mock"; | ||
|
||
import api from "./index"; | ||
import { ApiResponse, Child, PastSession } from "./types"; | ||
|
||
enableFetchMocks(); | ||
|
||
test("Show that retrieveChild is responding with expected data", async () => { | ||
// Use date as id to show that the data isn't manufactured. | ||
const child = { id: new Date().toString() } as Child; | ||
const data: ApiResponse<Child> = { data: child }; | ||
|
||
fetchMock.mockOnce(JSON.stringify(data)); | ||
|
||
const retrieveChild = await api.retrieveChild("some uuid"); | ||
expect(child).toStrictEqual(retrieveChild); | ||
}); | ||
|
||
test("Show that retrievePastSessions is responding with expected data", async () => { | ||
// Use date as id to show that the data isn't manufactured. | ||
const pastSessions: PastSession[] = [ | ||
{ id: new Date().toString() } as PastSession, | ||
]; | ||
const data: ApiResponse<PastSession[]> = { data: pastSessions }; | ||
|
||
fetchMock.mockOnce(JSON.stringify(data)); | ||
|
||
const retrievePastSessions = await api.retrievePastSessions("some uuid"); | ||
expect(pastSessions).toStrictEqual(retrievePastSessions); | ||
}); |
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,12 @@ | ||
import { ApiResponse, Child, PastSession } from "./types"; | ||
import { get } from "./utils"; | ||
|
||
async function retrieveChild(uuid: string) { | ||
return (await get<ApiResponse<Child>>(`children/${uuid}/`)).data; | ||
} | ||
|
||
async function retrievePastSessions(uuid: string) { | ||
return (await get<ApiResponse<PastSession[]>>(`past-sessions/${uuid}/`)).data; | ||
} | ||
|
||
export default { retrieveChild, retrievePastSessions }; |
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,76 @@ | ||
export type Relationship = { | ||
links: { | ||
related: string; | ||
}; | ||
}; | ||
|
||
export type Attributes = { | ||
readonly pk?: number; | ||
readonly url?: string; | ||
}; | ||
|
||
export interface Relationships {} | ||
|
||
export interface ChildAttrs extends Attributes { | ||
given_name: string; | ||
birthday: string; | ||
gender: "m" | "f" | "o" | "na"; | ||
readonly age_at_birth?: string; | ||
additional_information?: string; | ||
readonly language_list?: string; | ||
readonly condition_list?: string; | ||
deleted?: boolean; | ||
former_lookit_profile_id?: string; | ||
readonly pk?: number; | ||
} | ||
|
||
export interface PastSessionAttrs extends Attributes { | ||
conditions?: Record<string, never>; | ||
global_event_timings?: Record<string, never>; | ||
exp_data?: Record<string, never>; | ||
sequence?: string[]; | ||
completed?: boolean; | ||
completed_consent_frame?: boolean; | ||
survey_consent?: boolean; | ||
readonly created_on?: string; | ||
is_preview?: boolean; | ||
readonly hash_child_id?: string; | ||
recording_method?: string; | ||
eligibility?: ( | ||
| "Eligible" | ||
| "Ineligible_TooYoung" | ||
| "Ineligible_TooOld" | ||
| "Ineligible_CriteriaExpression" | ||
| "Ineligible_Participation" | ||
)[]; | ||
} | ||
|
||
export interface Data<Attributes> { | ||
type: string; | ||
id: string; | ||
attributes: Attributes; | ||
relationships: Relationships; | ||
links: { | ||
self: string; | ||
}; | ||
} | ||
|
||
export interface ApiResponse<Data> { | ||
data: Data; | ||
} | ||
|
||
export interface Child extends Data<ChildAttrs> { | ||
type: "children"; | ||
relationships: { | ||
user: Relationship; | ||
}; | ||
} | ||
export interface PastSession extends Data<PastSessionAttrs> { | ||
type: "past_sessions"; | ||
relationships: { | ||
child: Relationship; | ||
user: Relationship; | ||
study: Relationship; | ||
demographic_snapshot: Relationship; | ||
}; | ||
} |
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,15 @@ | ||
const url_base = "/api/v2/"; | ||
|
||
export async function get<T>(url: string) { | ||
/** | ||
* Function for REST get. | ||
*/ | ||
|
||
const request = new Request(url_base + url, { | ||
method: "GET", | ||
mode: "same-origin", | ||
}); | ||
|
||
const response = await fetch(request); | ||
return response.json() as Promise<T>; | ||
} |
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,8 @@ | ||
{ | ||
"extends": "@jspsych/config/tsconfig.core.json", | ||
"compilerOptions": { | ||
"strict": true, | ||
"baseUrl": "." | ||
}, | ||
"include": ["src"] | ||
} |
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,3 @@ | ||
const config = require("@jspsych/config/jest").makePackageConfig(__dirname); | ||
config.moduleNameMapper = {}; | ||
module.exports = config; |
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,20 @@ | ||
{ | ||
"name": "@lookit/lookit-helpers", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "jest --coverage", | ||
"build": "rollup --config" | ||
}, | ||
"unpkg": "dist/index.browser.min.js", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@jspsych/config": "^2.0.0" | ||
} | ||
} |
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,3 @@ | ||
import { makeRollupConfig } from "@jspsych/config/rollup"; | ||
|
||
export default makeRollupConfig("lookitHelpers"); |
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,40 @@ | ||
import { ApiResponse, Child, PastSession } from "@lookit/lookit-api/dist/types"; | ||
import { enableFetchMocks } from "jest-fetch-mock"; | ||
|
||
import Helpers from "./index"; | ||
|
||
enableFetchMocks(); | ||
|
||
test("Show that helpers child method returns expected data", async () => { | ||
// Use date as given name to show that the data isn't manufactured. | ||
const child = { attributes: { given_name: new Date().toString() } } as Child; | ||
const data: ApiResponse<Child> = { data: child }; | ||
|
||
fetchMock.mockOnce(JSON.stringify(data)); | ||
|
||
const child_uuid = "child uuid"; | ||
const response_uuid = "response uuid"; | ||
const helpersChild = await new Helpers(child_uuid, response_uuid).child(); | ||
expect({ | ||
given_name: child.attributes.given_name, | ||
additional_information: child.attributes.additional_information, | ||
age_at_birth: child.attributes.age_at_birth, | ||
birthday: child.attributes.birthday, | ||
}).toStrictEqual(helpersChild); | ||
}); | ||
|
||
test("Show that helpers past sessions returns expected data", async () => { | ||
// Use date as id to show that the data isn't manufactured. | ||
const pastSessions = [{ id: new Date().toString() }] as PastSession[]; | ||
const data: ApiResponse<PastSession[]> = { data: pastSessions }; | ||
|
||
fetchMock.mockOnce(JSON.stringify(data)); | ||
|
||
const child_uuid = "child uuid"; | ||
const response_uuid = "response uuid"; | ||
const helpersPastSessions = await new Helpers( | ||
child_uuid, | ||
response_uuid, | ||
).pastSessions(); | ||
expect(pastSessions).toStrictEqual(helpersPastSessions); | ||
}); |
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,26 @@ | ||
import api from "@lookit/lookit-api"; | ||
|
||
import { ChildSubSet } from "./types"; | ||
|
||
class Helpers { | ||
child_uuid: string; | ||
response_uuid: string; | ||
|
||
constructor(child_uuid: string, response_uuid: string) { | ||
this.child_uuid = child_uuid; | ||
this.response_uuid = response_uuid; | ||
} | ||
|
||
async child(): Promise<ChildSubSet> { | ||
const child = await api.retrieveChild(this.child_uuid); | ||
const { given_name, birthday, age_at_birth, additional_information } = | ||
child.attributes; | ||
return { given_name, birthday, age_at_birth, additional_information }; | ||
} | ||
|
||
async pastSessions() { | ||
return await api.retrievePastSessions(this.response_uuid); | ||
} | ||
} | ||
|
||
export default Helpers; |
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,8 @@ | ||
import { Child } from "@lookit/lookit-api/dist/types"; | ||
|
||
export type ChildSubSet = { | ||
given_name: Child["attributes"]["given_name"]; | ||
birthday: Child["attributes"]["birthday"]; | ||
age_at_birth?: Child["attributes"]["age_at_birth"]; | ||
additional_information?: Child["attributes"]["additional_information"]; | ||
}; |
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,8 @@ | ||
{ | ||
"extends": "@jspsych/config/tsconfig.core.json", | ||
"compilerOptions": { | ||
"strict": true, | ||
"baseUrl": "." | ||
}, | ||
"include": ["src"] | ||
} |
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