Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
make attribute value serialization in db test independent form graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Nov 22, 2020
1 parent a001d63 commit 7f79c2f
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Configuration,
fillSystemAttributesDefaultValues,
fillDefaultValues,
serializeValues,
validateMutationPayload,
MUTATION_TYPE_CREATE,
MUTATION_TYPE_UPDATE,
Expand Down Expand Up @@ -62,6 +61,39 @@ export const disconnectDB = async () => {
await disconnectStorage();
};

const serializeAttributeValues = (
entity,
entityMutation,
payload,
model,
context,
) => {
const ret = {
...payload,
};

const entityAttributes = entity.getAttributes();

for (const attribute of Object.values(entityAttributes)) {
const attributeName = attribute.name;

if (attribute.serialize) {
if (typeof ret[attributeName] !== 'undefined') {
ret[attributeName] = attribute.serialize(
ret[attributeName],
ret,
entityMutation,
entity,
model,
context,
);
}
}
}

return ret;
};

export const mutate = async (entity, mutationName, payload, id, context) => {
const modelRegistry = StorageTypePostgres.getStorageModels();

Expand Down Expand Up @@ -117,7 +149,7 @@ export const mutate = async (entity, mutationName, payload, id, context) => {
);

if (entityMutation.type !== MUTATION_TYPE_DELETE) {
args.input[typeName] = serializeValues(
args.input[typeName] = serializeAttributeValues(
entity,
entityMutation,
args.input[typeName],
Expand Down

0 comments on commit 7f79c2f

Please sign in to comment.