Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Rename Purchaser to Buyer (#61)
Browse files Browse the repository at this point in the history
* rename order purchaser to buyer

* remove eslint disable

* store self address rather than alias in db

* remove unused buyer
  • Loading branch information
jonmattgray authored Jun 28, 2022
1 parent 91b9bd2 commit 224412f
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 52 deletions.
6 changes: 3 additions & 3 deletions app/api-v1/api-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const apiDoc = {
'Name of the OEM who owns the design of the recipe. This information is not stored directly on-chain',
type: 'string',
maxLength: 255,
example: 'PurchaserAlias',
example: 'BuyerAlias',
},
},
},
Expand Down Expand Up @@ -322,12 +322,12 @@ const apiDoc = {
description: 'local id of the purchase-order',
allOf: [{ $ref: '#/components/schemas/ObjectReference' }],
},
purchaser: {
buyer: {
description:
'Name of the submitter of the purchase-order. This information is not stored directly on-chain',
type: 'string',
maxLength: 255,
example: 'PurchaserAlias',
example: 'BuyerAlias',
},
status: {
type: 'string',
Expand Down
41 changes: 20 additions & 21 deletions app/api-v1/controllers/Order/__tests__/orders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { expect } = require('chai')
const { stub } = require('sinon')
const orderController = require('../index')
const db = require('../../../../db')
const identifyService = require('../../../services/identityService')
const identityService = require('../../../services/identityService')
const { BadRequestError, NotFoundError, IdentityError, NoTokenError } = require('../../../../utils/errors')
const { DSCP_API_HOST, DSCP_API_PORT } = require('../../../../env')

Expand Down Expand Up @@ -64,12 +64,9 @@ describe('order controller', () => {
describe('/order - post endpoint for creating order in local db', () => {
beforeEach(async () => {
stubs.getRecipeIds = stub(db, 'getRecipeByIDs').resolves(recipeExamples)
stubs.identityByAlias = stub(identifyService, 'getMemberByAlias')
.onFirstCall()
.resolves({ address: 'supplier-address' })
.onSecondCall()
.resolves({ alias: 'self-address' })
stubs.identitySelf = stub(identifyService, 'getMemberBySelf').resolves('self-address')
stubs.identityByAlias = stub(identityService, 'getMemberByAlias').resolves({ address: 'supplier-address' })
stubs.identityByAddress = stub(identityService, 'getMemberByAddress').resolves({ alias: 'self-alias' })
stubs.identitySelf = stub(identityService, 'getMemberBySelf').resolves('self-address')
stubs.insertOrder = stub(db, 'postOrderDb').resolves([
{
id: 'order-id',
Expand All @@ -81,6 +78,7 @@ describe('order controller', () => {
afterEach(() => {
stubs.getRecipeIds.restore()
stubs.identityByAlias.restore()
stubs.identityByAddress.restore()
stubs.identitySelf.restore()
stubs.insertOrder.restore()
})
Expand Down Expand Up @@ -112,7 +110,7 @@ describe('order controller', () => {
stubs.identityByAlias.rejects('some error - identity alias')
response = await postOrder({
body: {
supplier: 'supplier-address-req',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: recipeExamples.map((el) => el.id),
Expand All @@ -132,7 +130,7 @@ describe('order controller', () => {
stubs.getRecipeIds.resolves([])
response = await postOrder({
body: {
supplier: 'supplier-address-req',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: recipeExamples.map((el) => el.id),
Expand Down Expand Up @@ -161,7 +159,7 @@ describe('order controller', () => {

response = await postOrder({
body: {
supplier: 'supplier-address-req-mismatch',
supplier: 'supplier-alias-mismatch',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: recipeExamples.map((el) => el.id),
Expand Down Expand Up @@ -191,7 +189,7 @@ describe('order controller', () => {

response = await postOrder({
body: {
supplier: 'supplier-address-req',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: recipeExamples.map((el) => el.id),
Expand All @@ -210,7 +208,7 @@ describe('order controller', () => {

response = await postOrder({
body: {
supplier: 'supplier-address-req-mismatch',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: recipeExamples.map((el) => el.id),
Expand All @@ -225,7 +223,7 @@ describe('order controller', () => {
it('gets aliases from identity service', () => {
expect(stubs.identityByAlias.getCall(0).args[0]).to.deep.equal({
body: {
supplier: 'supplier-address-req-mismatch',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: [
Expand All @@ -235,9 +233,9 @@ describe('order controller', () => {
],
},
})
expect(stubs.identityByAlias.getCall(1).args[0]).to.deep.equal({
expect(stubs.identityByAddress.getCall(0).args[0]).to.deep.equal({
body: {
supplier: 'supplier-address-req-mismatch',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: [
Expand All @@ -252,7 +250,7 @@ describe('order controller', () => {
it('retrieves self address', () => {
expect(stubs.identitySelf.getCall(0).args[0]).to.deep.equal({
body: {
supplier: 'supplier-address-req-mismatch',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: [
Expand All @@ -266,27 +264,28 @@ describe('order controller', () => {

it('validates properties by calling a helper method [validate]', () => {
expect(stubs.insertOrder.getCall(0).args[0]).to.deep.equal({
supplier: 'supplier-address',
supplier: 'supplier-alias',
supplierAddress: 'supplier-address',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
items: [
'50000000-0000-1000-5500-000000000001',
'50000000-0000-1000-5600-000000000001',
'50000000-0000-1000-5700-000000000001',
],
purchaserAddress: 'self-address',
status: 'Created',
purchaser: 'self-address',
buyerAddress: 'self-address',
})
})

it('persist order and returns 201 along with other details', () => {
expect(response.status).to.equal(201)
expect(response.response).to.deep.equal({
id: 'order-id',
supplier: 'supplier-address-req-mismatch',
supplier: 'supplier-alias',
description: 'some description - test',
requiredBy: '2022-06-17T07:31:37.602Z',
buyer: 'self-alias',
items: [
'50000000-0000-1000-5500-000000000001',
'50000000-0000-1000-5600-000000000001',
Expand Down Expand Up @@ -331,7 +330,7 @@ describe('order controller', () => {
stubs.insertTransaction = stub(db, 'insertOrderTransaction').resolves([])
stubs.getRecipeIds = stub(db, 'getRecipeByIDs').resolves(recipeExamples)
stubs.getOrder = stub(db, 'getOrder').resolves([])
stubs.getSelf = stub(identifyService, 'getMemberBySelf').resolves(null)
stubs.getSelf = stub(identityService, 'getMemberBySelf').resolves(null)
})
afterEach(() => {
stubs.getSelf.restore()
Expand Down
2 changes: 1 addition & 1 deletion app/api-v1/controllers/Order/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.validate = async (body) => {
throw new BadRequestError('recipe not found')
} else {
recipes.map((recipeItem) => {
if (recipeItem.supplier != body.supplier) {
if (recipeItem.supplier != body.supplierAddress) {
throw new BadRequestError('invalid supplier')
}
})
Expand Down
8 changes: 4 additions & 4 deletions app/api-v1/controllers/Order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ module.exports = {

const { address: supplierAddress } = await identity.getMemberByAlias(req, req.body.supplier)
const selfAddress = await identity.getMemberBySelf(req)
const { alias: selfAlias } = await identity.getMemberByAlias(req, selfAddress)
const { alias: selfAlias } = await identity.getMemberByAddress(req, selfAddress)

const validated = await validate({
...req.body,
supplier: supplierAddress,
purchaserAddress: selfAlias,
supplierAddress: supplierAddress,
status: 'Created',
purchaser: selfAddress,
buyerAddress: selfAddress,
})
const [result] = await db.postOrderDb(validated)

return {
status: 201,
response: {
...result,
buyer: selfAlias,
...req.body,
},
}
Expand Down
6 changes: 3 additions & 3 deletions app/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const client = knex({
async function postOrderDb(reqBody) {
return client('orders')
.insert({
supplier: reqBody.supplier,
supplier: reqBody.supplierAddress,
required_by: reqBody.requiredBy,
items: reqBody.items,
purchaser: reqBody.purchaserAddress,
buyer: reqBody.buyerAddress,
status: reqBody.status,
})
.returning('*')
.returning(['id', 'status'])
}

async function getAttachment(id) {
Expand Down
4 changes: 2 additions & 2 deletions helm/inteli-api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: inteli-api
appVersion: '1.27.0'
appVersion: '1.27.1'
description: A Helm chart for inteli-api
version: '1.27.0'
version: '1.27.1'
type: application
maintainers:
- name: digicatapult
Expand Down
2 changes: 1 addition & 1 deletion helm/inteli-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ingress:
image:
repository: ghcr.io/digicatapult/inteli-api
pullPolicy: IfNotPresent
tag: 'v1.27.0'
tag: 'v1.27.1'
pullSecrets: ['ghcr-digicatapult']

postgresql:
Expand Down
19 changes: 19 additions & 0 deletions migrations/20220626162554_rename_order_purchaser_to_buyer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async (knex) => {
await knex.schema.alterTable('orders', (def) => {
def.renameColumn('purchaser', 'buyer')
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async (knex) => {
await knex.schema.alterTable('orders', (def) => {
def.renameColumn('buyer', 'purchaser')
})
}
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,6 +1,6 @@
{
"name": "@digicatapult/inteli-api",
"version": "1.27.0",
"version": "1.27.1",
"description": "Insert repo description",
"main": "app/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describeAuthOnly('order - authenticated', function () {
}
const response = await postOrderRoute(newOrder, app, authToken)
expect(response.body.supplier).to.equal('valid-1')
expect(response.body.purchaser).to.equal('valid-2')
expect(response.body.buyer).to.equal('valid-2')
expect(response.body.items).to.contain('10000000-0000-1000-8000-000000000000')
expect(response.status).to.equal(201)
})
Expand Down Expand Up @@ -159,7 +159,7 @@ describeNoAuthOnly('order - no auth', function () {
}
const response = await postOrderRoute(newOrder, app, null)
expect(response.body.supplier).to.equal('valid-1')
expect(response.body.purchaser).to.equal('valid-2')
expect(response.body.buyer).to.equal('valid-2')
expect(response.body.items).to.contain('10000000-0000-1000-8000-000000000000')
expect(response.status).to.equal(201)
})
Expand Down
27 changes: 15 additions & 12 deletions test/seeds/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,28 @@ const seed = async () => {
},
])

/* eslint-disable */
await Promise.all(['Created', 'Submitted', 'Rejected', 'Accepted', 'Amended'].map((status, i) => client('orders').insert([{
id: `36345f4f-6535-42e2-83f9-79e2e195e11${i}`,
supplier: '36345f4f-0000-42e2-83f9-79e2e195e000',
items: ['10000000-0000-1000-9000-000000000000'],
purchaser: '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY',
status,
required_by: '2022-10-21T10:10:10.919Z',
},
])))
/* eslint-enable */
await Promise.all(
['Created', 'Submitted', 'Rejected', 'Accepted', 'Amended'].map((status, i) =>
client('orders').insert([
{
id: `36345f4f-6535-42e2-83f9-79e2e195e11${i}`,
supplier: '36345f4f-0000-42e2-83f9-79e2e195e000',
items: ['10000000-0000-1000-9000-000000000000'],
buyer: '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY',
status,
required_by: '2022-10-21T10:10:10.919Z',
},
])
)
)

// with recipe that does not have a token_id
await client('orders').insert([
{
id: '36345f4f-6535-42e2-83f9-79e2e195e101',
supplier: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
items: ['10000000-0000-1000-9000-000000000000'],
purchaser: '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY',
buyer: '5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY',
status: 'Created',
required_by: '2022-10-21T11:45:46.919Z',
},
Expand Down

0 comments on commit 224412f

Please sign in to comment.