Skip to content

Commit

Permalink
Swapping type to @type and fixing all tests and related fields, begin…
Browse files Browse the repository at this point in the history
…ning documentation of metadata
  • Loading branch information
vzhang03 committed Jun 27, 2024
1 parent e7a4ad9 commit d5815a2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
Empty file.
4 changes: 2 additions & 2 deletions packages/metadata/src/AuthorsMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
export interface AuthorFields {
/** The type of the author. */
type?: string;
"@type"?: string;
/** The name of the author. (required) */
name: string;
/** The given name of the author. */
Expand Down Expand Up @@ -86,7 +86,7 @@ export class AuthorsMap {
this.authors[name] = newAuthor;

const unexpectedFields = Object.keys(author).filter(
(key) => !["type", "name", "givenName", "familyName", "identifier"].includes(key)
(key) => !["@type", "name", "givenName", "familyName", "identifier"].includes(key)
);
if (unexpectedFields.length > 0) {
console.warn(
Expand Down
10 changes: 5 additions & 5 deletions packages/metadata/src/VariablesMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @typedef {VariableFields}
*/
export interface VariableFields {
type?: string;
"@type"?: string;
name: string; // required
description?: string | Record<string, string>;
value?: string; // string, boolean, or number
Expand Down Expand Up @@ -56,7 +56,7 @@ export class VariablesMap {
this.variables = {};

const trial_type_var: VariableFields = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "unknown",
Expand All @@ -67,7 +67,7 @@ export class VariablesMap {
this.setVariable(trial_type_var);

const trial_index_var: VariableFields = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_index",
description: {
default: "unknown",
Expand All @@ -78,7 +78,7 @@ export class VariablesMap {
this.setVariable(trial_index_var);

const time_elapsed_var: VariableFields = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "time_elapsed",
description: {
default: "unknown",
Expand Down Expand Up @@ -146,7 +146,7 @@ export class VariablesMap {
const unexpectedFields = Object.keys(variable).filter(
(key) =>
![
"type",
"@type",
"name",
"description",
"value",
Expand Down
4 changes: 2 additions & 2 deletions packages/metadata/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class JsPsychMetadata {
* as a way to update fields.
*
* @param {{
* type?: string;
* @type?: string;
* name: string; // required
* description?: string | {};
* value?: string; // string, boolean, or number
Expand Down Expand Up @@ -324,7 +324,7 @@ export default class JsPsychMetadata {
if (!this.containsVariable(variable)) {
// probs should have update description called here
const new_var = {
type: "PropertyValue",
"@type": "PropertyValue",
name: variable,
description: { default: "unknown" },
value: type,
Expand Down
34 changes: 17 additions & 17 deletions packages/metadata/tests/metadata-maps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ let author_data = [
name: "Barrack Obama",
},
{
type: "Author",
"@type": "Author",
name: "Donald Trump",
},
{
type: "Contributor",
"@type": "Contributor",
name: "Stan Johnson",
givenName: "Julio Jones",
familyName: "Aaron",
Expand All @@ -42,7 +42,7 @@ describe("AuthorsMap", () => {

test("#setOverwrite", () => {
const newJohnCena = {
type: "WWE Pro Wrestler",
"@type": "WWE Pro Wrestler",
name: "John Cena",
};

Expand All @@ -64,7 +64,7 @@ describe("AuthorsMap", () => {

const variable_data: VariableFields[] = [
{
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "unknown",
Expand All @@ -73,7 +73,7 @@ const variable_data: VariableFields[] = [
value: "string",
},
{
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_index",
description: {
default: "unknown",
Expand All @@ -82,7 +82,7 @@ const variable_data: VariableFields[] = [
value: "numeric",
},
{
type: "PropertyValue",
"@type": "PropertyValue",
name: "time_elapsed",
description: {
default: "unknown",
Expand All @@ -108,7 +108,7 @@ describe("VariablesMap", () => {

test("#setOverwrite", () => {
const newTrialType: VariableFields = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "different fields",
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("VariablesMap", () => {
// // updating normal variable (exists and doesn't exist)
test("#updateNormalVariables", () => {
const compare = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "unknown",
Expand All @@ -169,15 +169,15 @@ describe("VariablesMap", () => {

test("#updateLevels", () => {
interface Compare {
type: string;
"@type": string;
name: string;
description: {};
value: string;
levels: any[]; // Use specific type if known, e.g., string[] if levels contain strings
}

const compare: Compare = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "unknown",
Expand Down Expand Up @@ -205,7 +205,7 @@ describe("VariablesMap", () => {
// // updating name (checking references)
test("#updatingName", () => {
const compare = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "unknown",
Expand All @@ -227,7 +227,7 @@ describe("VariablesMap", () => {
}

let one_key_string = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "animation style",
description: "unknown",
value: "string",
Expand All @@ -243,7 +243,7 @@ describe("VariablesMap", () => {
}

let two_key = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "animation style",
description: {
grown: "how tall the user is",
Expand All @@ -262,7 +262,7 @@ describe("VariablesMap", () => {
}

let add_default = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "animation style",
description: {
default: "how tall the user is",
Expand All @@ -272,7 +272,7 @@ describe("VariablesMap", () => {
};

let expected = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "animation style",
description: "what the user likes to eat",
value: "string",
Expand All @@ -288,7 +288,7 @@ describe("VariablesMap", () => {
}

let add_default = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "animation style",
description: {
default: "how tall the user is",
Expand All @@ -299,7 +299,7 @@ describe("VariablesMap", () => {
};

let expected = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "animation style",
description: {
diet: "what the user likes to eat",
Expand Down
6 changes: 3 additions & 3 deletions packages/metadata/tests/metadata-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("JsPsychMetadata", () => {

test("#setAndGetVariable", () => {
const trialType = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: "Plugin type that has been used to run trials",
value: "string",
Expand All @@ -51,7 +51,7 @@ describe("JsPsychMetadata", () => {

test("#deleteVariable", () => {
const trialType = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: "Plugin type that has been used to run trials",
value: "string",
Expand All @@ -64,7 +64,7 @@ describe("JsPsychMetadata", () => {

test("#updateVariable", () => {
const trialType = {
type: "PropertyValue",
"@type": "PropertyValue",
name: "trial_type",
description: {
default: "unknown",
Expand Down

0 comments on commit d5815a2

Please sign in to comment.