Skip to content

Commit

Permalink
Advanced collection (#45)
Browse files Browse the repository at this point in the history

* fixed colision in object id + empty remote collection handling
  • Loading branch information
barduinor authored Oct 5, 2023
1 parent 1965801 commit a3126c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
Binary file removed .DS_Store
Binary file not shown.
19 changes: 13 additions & 6 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ class Collection {
*/
process () {
console.log('Processing collection')
const info = this.getInfo()
this.collectionId = info._postman_id
const item = this.getItems()
const variable = this.getVariables()
const auth = this.defaultAuth()
const collection = {
info: this.getInfo(),
item: this.getItems(),
info: info,
item: item,
event: [],
variable: this.getVariables(),
auth: this.defaultAuth()
variable: variable,
auth: auth
}
console.log('Done')
return collection
Expand Down Expand Up @@ -206,7 +211,7 @@ class Collection {
item: []

}
const folderId = Utils.GenID(JSON.stringify(folder))
const folderId = Utils.GenID(this.collectionId + JSON.stringify(folder))
folder.id = folderId
if (this.verbose) {
console.log(` Adding Folder [${folder.name}]`)
Expand Down Expand Up @@ -234,7 +239,9 @@ class Collection {
event: this.getItemEvents(endpoint)
}

const itemId = Utils.GenID(JSON.stringify(item))
// RB: This should pickup a different object id
// unexpected object id collision
const itemId = Utils.GenID(this.collectionId + JSON.stringify(item))
item.id = itemId
item.request = this.requestCreate(verb, path, endpoint, item.id)
item.response = this.responseCreate(endpoint, item.request.id)
Expand Down
17 changes: 12 additions & 5 deletions src/CollectionAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ class CollectionAdvanced extends Collection {
*/
// RB: override
process () {
console.log('Processing collection')
const info = this.getInfo()
this.collectionId = info._postman_id
const item = this.getItems()
const event = [this.collectionPreRequest()]
const variable = this.getVariables()
const auth = this.defaultAuth()
const localCollection = {
info: this.getInfo(),
item: this.getItems(),
event: [this.collectionPreRequest()],
variable: this.getVariables(),
auth: this.defaultAuth()
info,
item,
event,
variable,
auth
}

// RB: inject utilities
Expand Down
15 changes: 13 additions & 2 deletions src/DeployIncremental.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,19 @@ const checkObjectChanges = (remoteCollectionObject, localCollectionObject) => {
}

const checkScriptChanges = (scriptType, remoteCollection, localCollection) => {
const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType)
const localScript = localCollection.event.find(event => event.listen === scriptType)
// RB 2020-10-20: The collection may be empty or have no events at all
let remoteScript = null
let localScript = null
if (remoteCollection.collection.event) {
remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType)
}

if (localCollection.event) {
localScript = localCollection.event.find(event => event.listen === scriptType)
}

// const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType)
// const localScript = localCollection.event.find(event => event.listen === scriptType)

if (!remoteScript && !localScript) {
return false
Expand Down

0 comments on commit a3126c2

Please sign in to comment.