Skip to content

Commit

Permalink
Merge pull request #2 from hckrnews/feature/phase1
Browse files Browse the repository at this point in the history
Add the schema for the product after normalizing
  • Loading branch information
w3nl authored Feb 2, 2022
2 parents ded9015 + 26ed785 commit 446e5c6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ or
```javascript
import makeNormalizer from '@hckrnews/normalizer';

const schema = {
const schemaFrom = {
pim_sku: String,
pim_productgroupname: String
}
const Normalizer = makeNormalizer({ schema })
const schemaTo = {
sku: String,
group: {
name: String
}
}
const Normalizer = makeNormalizer({ schemaFrom, schemaTo })

const normalizer = new Normalizer()

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hckrnews/normalizer",
"description": "Normalizer objects",
"version": "0.1.0",
"version": "0.2.0",
"author": {
"name": "Pieter Wigboldus",
"url": "https://hckr.news/"
Expand Down
12 changes: 9 additions & 3 deletions src/__tests__/normalizer.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ describe('Filter', () => {
pim_sku: String,
pim_productgroupname: String
}
const productSchema = {
sku: String,
group: {
name: String
}
};
const rawData = [
{
pim_sku: '123',
Expand All @@ -19,7 +25,7 @@ describe('Filter', () => {
name: data.pim_productgroupname
}
})
const Normalizer = makeNormalizer({ schema })
const Normalizer = makeNormalizer({ schemaFrom: schema, schemaTo: productSchema })
const normalizer = new Normalizer()
normalizer.data = rawData
normalizer.mapping = mapping
Expand All @@ -37,7 +43,7 @@ describe('Filter', () => {
})

it('It should throw an exception if the mapping isnt a function', () => {
const Normalizer = makeNormalizer({ schema: {} })
const Normalizer = makeNormalizer({ schemaFrom: {}, schemaTo: {} })
const normalizer = new Normalizer()
expect(() => {
normalizer.mapping = 42
Expand All @@ -56,7 +62,7 @@ describe('Filter', () => {
}
]

const Normalizer = makeNormalizer({ schema })
const Normalizer = makeNormalizer({ schemaFrom: schema, schemaTo: {} })
const normalizer = new Normalizer()
expect(() => {
normalizer.data = rawData
Expand Down
11 changes: 3 additions & 8 deletions src/normalizer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import Obj from '@hckrnews/objects';

const productSchema = {
sku: String,
};

const Product = Obj({ schema: productSchema });

export default ({ schema }) => {
const RawProduct = Obj({ schema });
export default ({ schemaFrom, schemaTo }) => {
const RawProduct = Obj({ schema: schemaFrom });
const Product = Obj({ schema: schemaTo });

return class Normalizer {
/** @type {string[]} data */
Expand Down

0 comments on commit 446e5c6

Please sign in to comment.