Skip to content

Commit

Permalink
Merge branch 'release-4.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Nov 29, 2018
2 parents 483d6d5 + fc1fb12 commit 9842676
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [4.4.3] (2018-11-29)

### Fixed

- [#519](https://github.com/dadi/api/pull/519): add URL property to composed Media values

## [4.4.2] (2018-11-29)

### Fixed
Expand Down
8 changes: 7 additions & 1 deletion dadi/lib/fields/media.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const path = require('path')
const mediaModel = require(
path.join(__dirname, '/../model/media')
)

module.exports.type = 'media'

module.exports.beforeOutput = function ({
Expand Down Expand Up @@ -64,8 +69,9 @@ module.exports.beforeOutput = function ({
return id
})
}).then(composedValue => {
let formattedValue = mediaModel.formatDocuments(composedValue)
let output = Object.assign(input, {
[field]: isArraySyntax ? composedValue : composedValue[0]
[field]: isArraySyntax ? formattedValue : formattedValue[0]
})

if (composedIDs.length > 0) {
Expand Down
10 changes: 7 additions & 3 deletions dadi/lib/fields/reference.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const path = require('path')
const mediaModel = require(
path.join(__dirname, '/../model/media')
)

module.exports.type = 'reference'

Expand Down Expand Up @@ -170,10 +173,11 @@ module.exports.beforeOutput = function ({
// This isn't great. I'd like to move away from the
// `mediaStore` magic string in favour of an `Image`
// field type (https://github.com/dadi/api/issues/415).
//
// Update (Nov 18): We have the Media field in place now,
// but we must keep this for backwards-compatibility.
if (collection === 'mediaStore') {
result = require(
path.join(__dirname, '/../model/media')
).formatDocuments(result)
result = mediaModel.formatDocuments(result)
}

let nextData = Object.assign({}, arguments[0], {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dadi/api",
"version": "4.4.2",
"version": "4.4.3",
"main": "main.js",
"scripts": {
"create-client": "cd ../../.. && node ./node_modules/@dadi/api/utils/create-client.js",
Expand Down
30 changes: 30 additions & 0 deletions test/acceptance/fields/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject._id)

client
Expand All @@ -298,6 +299,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject._id)

done(err)
Expand Down Expand Up @@ -345,8 +347,10 @@ describe('Media field', () => {
results[0].leadImage.length.should.eql(2)
results[0].leadImage[0]._id.should.eql(mediaObject1._id)
results[0].leadImage[0].fileName.should.eql('1f525.png')
results[0].leadImage[0].url.should.be.instanceOf(String)
results[0].leadImage[1]._id.should.eql(mediaObject2._id)
results[0].leadImage[1].fileName.should.eql('flowers.jpg')
results[0].leadImage[1].url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql([
mediaObject1._id,
mediaObject2._id
Expand All @@ -366,8 +370,10 @@ describe('Media field', () => {
results[0].leadImage.length.should.eql(2)
results[0].leadImage[0]._id.should.eql(mediaObject1._id)
results[0].leadImage[0].fileName.should.eql('1f525.png')
results[0].leadImage[0].url.should.be.instanceOf(String)
results[0].leadImage[1]._id.should.eql(mediaObject2._id)
results[0].leadImage[1].fileName.should.eql('flowers.jpg')
results[0].leadImage[1].url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql([
mediaObject1._id,
mediaObject2._id
Expand Down Expand Up @@ -445,6 +451,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject._id)

client
Expand All @@ -459,6 +466,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject._id)

done(err)
Expand Down Expand Up @@ -506,8 +514,10 @@ describe('Media field', () => {
results[0].leadImage.length.should.eql(2)
results[0].leadImage[0]._id.should.eql(mediaObject1._id)
results[0].leadImage[0].fileName.should.eql('1f525.png')
results[0].leadImage[0].url.should.be.instanceOf(String)
results[0].leadImage[1]._id.should.eql(mediaObject2._id)
results[0].leadImage[1].fileName.should.eql('flowers.jpg')
results[0].leadImage[1].url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql([
mediaObject1._id,
mediaObject2._id
Expand All @@ -527,8 +537,10 @@ describe('Media field', () => {
results[0].leadImage.length.should.eql(2)
results[0].leadImage[0]._id.should.eql(mediaObject1._id)
results[0].leadImage[0].fileName.should.eql('1f525.png')
results[0].leadImage[0].url.should.be.instanceOf(String)
results[0].leadImage[1]._id.should.eql(mediaObject2._id)
results[0].leadImage[1].fileName.should.eql('flowers.jpg')
results[0].leadImage[1].url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql([
mediaObject1._id,
mediaObject2._id
Expand Down Expand Up @@ -573,6 +585,7 @@ describe('Media field', () => {
results[0].leadImage.altText.should.eql(payload.leadImage.altText)
results[0].leadImage.crop.should.eql(payload.leadImage.crop)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject._id)

client
Expand All @@ -590,6 +603,7 @@ describe('Media field', () => {
results[0].leadImage.altText.should.eql(payload.leadImage.altText)
results[0].leadImage.crop.should.eql(payload.leadImage.crop)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject._id)

done(err)
Expand Down Expand Up @@ -643,9 +657,11 @@ describe('Media field', () => {
results[0].leadImage.length.should.eql(2)
results[0].leadImage[0]._id.should.eql(mediaObject1._id)
results[0].leadImage[0].fileName.should.eql('1f525.png')
results[0].leadImage[0].url.should.be.instanceOf(String)
results[0].leadImage[0].caption.should.eql(payload.leadImage[0].caption)
results[0].leadImage[1]._id.should.eql(mediaObject2._id)
results[0].leadImage[1].fileName.should.eql('flowers.jpg')
results[0].leadImage[1].url.should.be.instanceOf(String)
results[0].leadImage[1].caption.should.eql(payload.leadImage[1].caption)
results[0]._composed.leadImage.should.eql([
mediaObject1._id,
Expand All @@ -666,9 +682,11 @@ describe('Media field', () => {
results[0].leadImage.length.should.eql(2)
results[0].leadImage[0]._id.should.eql(mediaObject1._id)
results[0].leadImage[0].fileName.should.eql('1f525.png')
results[0].leadImage[0].url.should.be.instanceOf(String)
results[0].leadImage[0].caption.should.eql(payload.leadImage[0].caption)
results[0].leadImage[1]._id.should.eql(mediaObject2._id)
results[0].leadImage[1].fileName.should.eql('flowers.jpg')
results[0].leadImage[1].url.should.be.instanceOf(String)
results[0].leadImage[1].caption.should.eql(payload.leadImage[1].caption)
results[0]._composed.leadImage.should.eql([
mediaObject1._id,
Expand Down Expand Up @@ -708,6 +726,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].legacyImage._id.should.eql(mediaObject._id)
results[0].legacyImage.fileName.should.eql('1f525.png')
results[0].legacyImage.url.should.be.instanceOf(String)
results[0]._composed.legacyImage.should.eql(mediaObject._id)

client
Expand All @@ -722,6 +741,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].legacyImage._id.should.eql(mediaObject._id)
results[0].legacyImage.fileName.should.eql('1f525.png')
results[0].legacyImage.url.should.be.instanceOf(String)
results[0]._composed.legacyImage.should.eql(mediaObject._id)

let collectionSchemaPath = path.join(
Expand Down Expand Up @@ -751,6 +771,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].legacyImage._id.should.eql(mediaObject._id)
results[0].legacyImage.fileName.should.eql('1f525.png')
results[0].legacyImage.url.should.be.instanceOf(String)
results[0]._composed.legacyImage.should.eql(mediaObject._id)

restoreCollection()
Expand Down Expand Up @@ -910,6 +931,7 @@ describe('Media field', () => {
res.body.results[0].title.should.eql(payload1.title)
res.body.results[0].leadImageJPEG._id.should.eql(mediaObject._id)
res.body.results[0].leadImageJPEG.fileName.should.eql('flowers.jpg')
res.body.results[0].leadImageJPEG.url.should.be.instanceOf(String)
res.body.results[0]._composed.leadImageJPEG.should.eql(mediaObject._id)

done(err)
Expand Down Expand Up @@ -1046,6 +1068,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)

let updatePayload = {
leadImage: 'QWERTYUIOP'
Expand Down Expand Up @@ -1102,6 +1125,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject1._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject1._id)

let updatePayload = {
Expand All @@ -1126,6 +1150,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject2._id)
results[0].leadImage.fileName.should.eql('flowers.jpg')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject2._id)

done(err)
Expand Down Expand Up @@ -1162,6 +1187,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)

let updatePayload = {
leadImage: {
Expand Down Expand Up @@ -1220,6 +1246,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject1._id)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject1._id)

let updatePayload = {
Expand All @@ -1246,6 +1273,7 @@ describe('Media field', () => {
results[0].title.should.eql(payload.title)
results[0].leadImage._id.should.eql(mediaObject2._id)
results[0].leadImage.fileName.should.eql('flowers.jpg')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject2._id)

done(err)
Expand Down Expand Up @@ -1296,6 +1324,7 @@ describe('Media field', () => {
results[0].leadImage.altText.should.eql(payload.leadImage.altText)
results[0].leadImage.caption.should.eql(payload.leadImage.caption)
results[0].leadImage.fileName.should.eql('1f525.png')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject1._id)

let updatePayload = {
Expand Down Expand Up @@ -1327,6 +1356,7 @@ describe('Media field', () => {
results[0].leadImage.crop.should.eql(updatePayload.leadImage.crop)
should.not.exist(results[0].leadImage.caption)
results[0].leadImage.fileName.should.eql('flowers.jpg')
results[0].leadImage.url.should.be.instanceOf(String)
results[0]._composed.leadImage.should.eql(mediaObject2._id)

done(err)
Expand Down

0 comments on commit 9842676

Please sign in to comment.