-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6791 from reactioncommerce/fix/assigning-first-se…
…quence fix: unable to assigning first sequence with sample data
- Loading branch information
Showing
9 changed files
with
102 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/api-plugin-sample-data/src/loaders/loadSequences.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
import Random from "@reactioncommerce/random"; | ||
import config from "../config.js"; | ||
|
||
const { SEQUENCE_INITIAL_VALUES } = config; | ||
|
||
/** | ||
* @summary load Sequences data | ||
* @param {Object} context - The application context | ||
* @param {String} shopId - The Shop ID | ||
* @returns {void} | ||
*/ | ||
export default async function loadSequences(context, shopId) { | ||
const { sequenceConfigs, collections: { Sequences } } = context; | ||
if (sequenceConfigs.length === 0) return; | ||
|
||
for (const sequence of sequenceConfigs) { | ||
const { entity } = sequence; | ||
const existingSequence = await Sequences.findOne({ shopId, entity }); | ||
if (!existingSequence) { | ||
const startingValue = SEQUENCE_INITIAL_VALUES[entity] || 1000000; | ||
await Sequences.insertOne({ | ||
_id: Random.id(), | ||
shopId, | ||
entity, | ||
value: startingValue | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@reactioncommerce/api-utils/lib/configs/babel.config.cjs"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("@reactioncommerce/api-utils/lib/configs/jest.config.cjs"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/api-plugin-sequences/src/mutations/incrementSequence.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; | ||
import incrementSequence from "./incrementSequence.js"; | ||
|
||
test("incrementSequence returns a correct number", async () => { | ||
mockContext.collections = { | ||
Sequences: { | ||
findOneAndUpdate: jest.fn().mockReturnValueOnce(Promise.resolve({ | ||
value: { | ||
value: 1 | ||
} | ||
})) | ||
} | ||
}; | ||
|
||
const result = await incrementSequence(mockContext, "SHOP_ID", "ENTITY"); | ||
expect(result).toEqual(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters