@dooer/dooer-test-env 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/account.js CHANGED
@@ -50,10 +50,20 @@ async function createAccount({ local, name, ownerUserId, execute = false } = {})
50
50
  const client = new Client({ ...local, ssl: local.ssl === false ? undefined : { rejectUnauthorized: false } })
51
51
  await client.connect()
52
52
  try {
53
- const owner = await client.query('SELECT users_pk, email FROM service_accounts.users WHERE users_pk=$1', [
54
- ownerUserId,
55
- ])
53
+ // user_type is the fk_user_roles_at_dooer_pk column (User model). Only 'customer' users get a
54
+ // type:'customer' login token; a 'hi'/admin user is blocked from customer-only flows (e.g. accepting
55
+ // Terms of Service in sumify → "only-owner-can-accept-tos"). Warn if the owner isn't a customer.
56
+ const owner = await client.query(
57
+ 'SELECT users_pk, email, fk_user_roles_at_dooer_pk AS user_type FROM service_accounts.users WHERE users_pk=$1',
58
+ [ownerUserId]
59
+ )
56
60
  if (!owner.rowCount) throw new Error(`owner user ${ownerUserId} not found in the local DB (run \`db pull\` first?)`)
61
+ const ownerType = owner.rows[0].user_type
62
+ const warning =
63
+ ownerType === 'customer'
64
+ ? null
65
+ : `owner ${ownerUserId} is a '${ownerType}' user, not 'customer' — customer-only flows ` +
66
+ `(e.g. accepting Terms of Service in sumify) will fail. Use a customer user as the owner.`
57
67
 
58
68
  const partner = await client.query('SELECT id, name FROM service_accounts.partner WHERE domain=$1', [
59
69
  DEFAULT_PARTNER_DOMAIN,
@@ -67,8 +77,10 @@ async function createAccount({ local, name, ownerUserId, execute = false } = {})
67
77
  name,
68
78
  shortName,
69
79
  owner: owner.rows[0].email,
80
+ ownerType,
70
81
  partner: DEFAULT_PARTNER_DOMAIN,
71
82
  subscriptions: SUBSCRIPTION_TYPES,
83
+ warning,
72
84
  }
73
85
  if (!execute) {
74
86
  console.log('DRY-RUN (pass --execute to create):')
@@ -78,10 +90,12 @@ async function createAccount({ local, name, ownerUserId, execute = false } = {})
78
90
 
79
91
  await client.query('BEGIN')
80
92
  await client.query(
93
+ // Populate a placeholder address: some org endpoints serialize organization.address as a required
94
+ // OBJECT and return null (schema violation, seen in sumify) when all address columns are empty.
81
95
  `INSERT INTO service_accounts.companies
82
96
  (companies_pk, fk_countries_pk, fk_company_types_pk, company_name, short_name, organization_number,
83
- api_uuid, language, "timeZone", currency, inserted_at, updated_at)
84
- VALUES ($1,'SE','AB',$2,$3,$4,$5,'sv','Europe/Stockholm','SEK',now(),now())`,
97
+ api_uuid, language, "timeZone", currency, address, postal_code, city, inserted_at, updated_at)
98
+ VALUES ($1,'SE','AB',$2,$3,$4,$5,'sv','Europe/Stockholm','SEK','Testgatan 1','11111','Stockholm',now(),now())`,
85
99
  [orgId, name, shortName, orgNumber(), uuid()]
86
100
  )
87
101
  await client.query(
@@ -96,10 +96,11 @@ module.exports = {
96
96
  console.log(chalk.green(`\ncreated account "${res.name}"`))
97
97
  console.log(` org id: ${res.orgId}`)
98
98
  console.log(` short name: ${res.shortName}`)
99
- console.log(` owner: ${argv.owner} (${res.owner}) — role Owner`)
99
+ console.log(` owner: ${argv.owner} (${res.owner}) — role Owner, user_type '${res.ownerType}'`)
100
100
  console.log(` partner: ${res.partner}`)
101
101
  console.log(` subscriptions: ${SUBSCRIPTION_TYPES.join(', ')} (active)`)
102
102
  }
103
+ if (res.warning) console.log(chalk.yellow(`\n⚠ ${res.warning}`))
103
104
  },
104
105
  })
105
106
  .demandCommand(1, 'Use: customer copy | customer purge | customer new')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooer/dooer-test-env",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Run the whole Dooer backend locally (staging DB minus customers), copy/purge customers between environments, and shred — one CLI.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": "Dooer/cli-dooer-test-env",