apps-consumer-utils
Advanced tools
Comparing version 1.0.6-0 to 1.0.7-0
23
index.js
@@ -5,2 +5,3 @@ "use strict"; | ||
const dedynamise = require('dynamodb-data-types').AttributeValue.unwrap; | ||
const tz = require('timezone/loaded'); | ||
@@ -18,2 +19,11 @@ module.exports = { | ||
// getLatestEventsById :: [Object] -> [Object] | ||
"getLatestEventsById": (records) => { | ||
const grouped = R.groupBy(record => { | ||
const dbKeys = dedynamise(record.dynamodb.Keys); | ||
return dbKeys.Id + dbKeys.Source; | ||
}, records); | ||
return R.values(R.map(R.last, grouped)); | ||
}, | ||
// getSource :: Object -> Object | ||
@@ -42,2 +52,5 @@ "normalizeJSON": (record) => { | ||
// getPlatform :: String -> String -> String | ||
'createId': R.curry((platform, id) => `${platform}.${id}`), | ||
// getSource :: Object -> String | ||
@@ -55,10 +68,4 @@ "getSource": getSource, | ||
// getLatestEventsById :: [Object] -> [Object] | ||
"getLatestEventsById": (records) => { | ||
const grouped = R.groupBy(record => { | ||
const dbKeys = dedynamise(record.dynamodb.Keys); | ||
return dbKeys.Id + dbKeys.Source; | ||
}, records); | ||
return R.values(R.map(R.last, grouped)); | ||
} | ||
// getLastModifiedDate :: Object -> String | ||
"formatTime": (unformattedTime) => tz(unformattedTime, '%Y-%m-%dT%H:%M:%S.%3N%:z', 'UTC') | ||
}; | ||
@@ -65,0 +72,0 @@ |
{ | ||
"name": "apps-consumer-utils", | ||
"version": "1.0.6-0", | ||
"version": "1.0.7-0", | ||
"description": "", | ||
@@ -15,3 +15,4 @@ "main": "index.js", | ||
"dynamodb-data-types": "3.0.1", | ||
"ramda": "0.27.0" | ||
"ramda": "0.27.0", | ||
"timezone": "1.0.23" | ||
}, | ||
@@ -18,0 +19,0 @@ "devDependencies": { |
@@ -56,5 +56,9 @@ # apps-consumer-utils | ||
### v 1.0.3 | ||
### v1.0.4 to v1.0.6 | ||
- added `getId`, `getHomeSectionId`, and `getPubId` utility functions | ||
### v1.0.3 | ||
- Added `getSource` utility function. | ||
- moved ramda version to `0.27.0` |
@@ -5,2 +5,3 @@ "use strict"; | ||
const assert = require("chai").assert; | ||
const tz = require('timezone/loaded'); | ||
@@ -15,5 +16,12 @@ describe("Chronos consumer utilities", () => { | ||
assert.equal(index.getId(content), 'nationals.123'); | ||
assert.strictEqual(index.getId(content), 'nationals.123'); | ||
}); | ||
}); | ||
describe('createId', () => { | ||
it('should get create platform specific ids', () => { | ||
assert.strictEqual(index.createId('nationals', 12345), 'nationals.12345'); | ||
assert.strictEqual(index.createId('regionals', 12345), 'regionals.12345'); | ||
}); | ||
}); | ||
@@ -24,3 +32,3 @@ describe('getSource', () => { | ||
assert.equal(index.getSource(content), 'nationals'); | ||
assert.strictEqual(index.getSource(content), 'nationals'); | ||
}); | ||
@@ -36,3 +44,3 @@ }); | ||
assert.equal(index.getHomeSectionId(content), 'nationals.456'); | ||
assert.strictEqual(index.getHomeSectionId(content), 'nationals.456'); | ||
}); | ||
@@ -48,6 +56,13 @@ }); | ||
assert.equal(index.getPubId(content), 'nationals.789'); | ||
assert.strictEqual(index.getPubId(content), 'nationals.789'); | ||
}); | ||
}); | ||
describe('formatTime', () => { | ||
it('should format the time', () => { | ||
assert.strictEqual(index.formatTime('1327625202000'), '2012-01-27T00:46:42.000+00:00'); | ||
assert.strictEqual(index.formatTime('1171324800000'), '2007-02-13T00:00:00.000+00:00'); | ||
assert.strictEqual(index.formatTime('1583930225000'), '2020-03-11T12:37:05.000+00:00'); | ||
}); | ||
}); | ||
@@ -164,3 +179,3 @@ describe('normalizeJSON', () => { | ||
assert.equal(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454601272000"); | ||
assert.strictEqual(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454601272000"); | ||
}); | ||
@@ -204,7 +219,7 @@ | ||
assert.equal(actual[0].dynamodb.Keys.Id.N, "666666"); | ||
assert.equal(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454601272000"); | ||
assert.strictEqual(actual[0].dynamodb.Keys.Id.N, "666666"); | ||
assert.strictEqual(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454601272000"); | ||
assert.equal(actual[1].dynamodb.Keys.Id.N, "666667"); | ||
assert.equal(actual[1].dynamodb.NewImage.LastModifiedTime.N, "1454601555555"); | ||
assert.strictEqual(actual[1].dynamodb.Keys.Id.N, "666667"); | ||
assert.strictEqual(actual[1].dynamodb.NewImage.LastModifiedTime.N, "1454601555555"); | ||
}); | ||
@@ -265,7 +280,7 @@ | ||
assert.equal(actual[0].dynamodb.Keys.Id.N, "666666"); | ||
assert.equal(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454701555000"); | ||
assert.strictEqual(actual[0].dynamodb.Keys.Id.N, "666666"); | ||
assert.strictEqual(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454701555000"); | ||
assert.equal(actual[1].dynamodb.Keys.Id.N, "666667"); | ||
assert.equal(actual[1].dynamodb.NewImage.LastModifiedTime.N, "1454601555555"); | ||
assert.strictEqual(actual[1].dynamodb.Keys.Id.N, "666667"); | ||
assert.strictEqual(actual[1].dynamodb.NewImage.LastModifiedTime.N, "1454601555555"); | ||
}); | ||
@@ -344,9 +359,9 @@ | ||
assert.equal(actual[0].dynamodb.Keys.Id.N, "666666"); | ||
assert.equal(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454701555000"); | ||
assert.strictEqual(actual[0].dynamodb.Keys.Id.N, "666666"); | ||
assert.strictEqual(actual[0].dynamodb.NewImage.LastModifiedTime.N, "1454701555000"); | ||
assert.equal(actual[1].dynamodb.Keys.Id.N,"666667"); | ||
assert.equal(actual[1].dynamodb.NewImage.LastModifiedTime.N,"1454801995000"); | ||
assert.strictEqual(actual[1].dynamodb.Keys.Id.N,"666667"); | ||
assert.strictEqual(actual[1].dynamodb.NewImage.LastModifiedTime.N,"1454801995000"); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
20577
414
63
3
+ Addedtimezone@1.0.23
+ Addedtimezone@1.0.23(transitive)