Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Adds s-s to the referral code #13756

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/cmdLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const fs = require('fs')
const path = require('path')

const isDarwin = process.platform === 'darwin'
const promoCodeFilenameRegex = /-([a-zA-Z\d]{3}\d{3})\s?(?:\(\d+\))?$/g
const debugTabEventsFlagName = '--debug-tab-events'

let appInitialized = false
Expand Down Expand Up @@ -166,8 +165,9 @@ const api = module.exports = {
// parse promo code from installer path
// first, get filename
const fileName = path.win32.parse(installerPath).name
const promoCodeFilenameRegex = /-(([a-zA-Z\d]{3}\d{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))\s?(?:\(\d+\))?$/g
const matches = promoCodeFilenameRegex.exec(fileName)
if (matches && matches.length === 2) {
if (matches && matches.length > 1) {
return matches[1]
}
return null
Expand Down
2 changes: 1 addition & 1 deletion build/pkg-scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ installationPath=$2
# TODO: ugly to assume the name of the app, especially with multi-channel.
# Luckily for now, release channel is the only channel with a pkg installer.
installationAppPath="$installationPath/Brave.app"
installerPathPromoCodeRegex='.+-([a-zA-Z0-9]{3}[0-9]{3})([[:blank:]]?\([0-9]+\))?\.pkg$'
installerPathPromoCodeRegex='.+-(([a-zA-Z0-9]{3}[0-9]{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))([[:blank:]]?\([0-9]+\))?\.pkg$'
userDataDir="$HOME/Library/Application Support/brave"
promoCodePath="$userDataDir/promoCode"
# pkg runs this script as root so we need to get current username
Expand Down
17 changes: 17 additions & 0 deletions build/pkg-scripts/postinstall-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
installerPath=$1
installerPathPromoCodeRegex='.+-(([a-zA-Z0-9]{3}[0-9]{3})|([a-zA-Z]{1,}-[a-zA-Z]{1,}))([[:blank:]]?\([0-9]+\))?\.pkg$'
echo "Installer path is: $installerPath"

if [[ $installerPath =~ $installerPathPromoCodeRegex ]]; then
echo "Installer path matched for promo code"
n=${#BASH_REMATCH[*]}
if [ $n -ge 1 ]; then
promoCode=${BASH_REMATCH[1]}
echo "Got promo code: $promoCode"
fi
else
echo "Installer path did not match for promo code"
fi

exit 0
25 changes: 25 additions & 0 deletions test/unit/app/cmdLineTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ describe('cmdLine', function () {
const result = this.cmdLine.getFirstRunPromoCode(args)
assert.equal(result, promoCode)
})

it('finds and parses promo code when we have multiple downloads', function () {
const promoCode = 'pem001 (1)'
const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe`
const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another']
const result = this.cmdLine.getFirstRunPromoCode(args)
assert.equal(result, 'pem001')
})

it('finds and parses promo code 2', function () {
const promoCode = 'org-name'
const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe`
const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another']
const result = this.cmdLine.getFirstRunPromoCode(args)
assert.equal(result, promoCode)
})

it('finds and parses promo code 2 when we have multiple downloads', function () {
const promoCode = 'org-name (1)'
const validPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64-${promoCode}.exe`
const args = [...initialArgs, key, validPromoCodeInstallerPath, '--other', 'arg', '--and-another']
const result = this.cmdLine.getFirstRunPromoCode(args)
assert.equal(result, 'org-name')
})

it(`does not find promo code when there isn't one`, function () {
const noPromoCodeInstallerPath = `d:\\my\\location\\on-disk\\in-a-folder-tes301\\Setup-Brave-x64.exe`
const args = [...initialArgs, key, noPromoCodeInstallerPath, '--other', 'arg', '--and-another']
Expand Down