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

Send week of installation and ref parameter to updater #12135

Merged
merged 2 commits into from
Dec 4, 2017
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
12 changes: 12 additions & 0 deletions app/dates.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

// The iso week is defined as the week number starting on January 4th indexed to the first Thursday
var isoWeek = function () {
var date = new Date()
Expand Down Expand Up @@ -30,3 +34,11 @@ exports.todayWOY = () => {
exports.todayMonth = () => {
return (new Date()).getMonth() + 1
}

const MILLISECONDS_IN_ONE_DAY = 60 * 60 * 24 * 1000

// return YYYY-MM-DD of closest Monday in the past to current date
exports.lastMonday = (d) => {
var monday = new Date(d.getTime() - ((d.getDay() - 1) * MILLISECONDS_IN_ONE_DAY))
return localYMD(monday)
}
15 changes: 12 additions & 3 deletions app/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const appActions = require('../js/actions/appActions')
const Immutable = require('immutable')
const dates = require('./dates')
const Channel = require('./channel')
const buildConfig = require('../js/constants/buildConfig')

const fs = require('fs')
const path = require('path')
Expand Down Expand Up @@ -117,12 +118,14 @@ exports.init = (platform, arch, ver, updateToPreview) => {
// This is a privacy preserving policy. Instead of passing personally identifying
// information, the browser will pass thefour boolean values indicating when the last
// update check occurred.
var paramsFromLastCheckDelta = (lastCheckYMD, lastCheckWOY, lastCheckMonth, firstCheckMade) => {
var paramsFromLastCheckDelta = (lastCheckYMD, lastCheckWOY, lastCheckMonth, firstCheckMade, weekOfInstallation, ref) => {
return {
daily: !lastCheckYMD || (dates.todayYMD() > lastCheckYMD),
weekly: !lastCheckWOY || (dates.todayWOY() !== lastCheckWOY),
monthly: !lastCheckMonth || (dates.todayMonth() !== lastCheckMonth),
first: !firstCheckMade
first: !firstCheckMade,
woi: weekOfInstallation,
ref: ref || null
}
}

Expand All @@ -143,12 +146,18 @@ var requestVersionInfo = (done, pingOnly) => {
const firstCheckMade = state.getIn(['updates', 'firstCheckMade'], false)
debug(`firstCheckMade = ${firstCheckMade}`)

// The previous Monday from the installation date
const weekOfInstallation = state.getIn(['updates', 'weekOfInstallation'], null)
debug(`weekOfInstallation= ${weekOfInstallation}`)

// Build query string based on the last date an update request was made
const query = paramsFromLastCheckDelta(
lastCheckYMD,
lastCheckWOY,
lastCheckMonth,
firstCheckMade
firstCheckMade,
weekOfInstallation,
buildConfig.ref || null
)
query.accept_preview = updateToPreviewReleases ? 'true' : 'false'
const queryString = `${platformBaseUrl}?${querystring.stringify(query)}`
Expand Down
3 changes: 3 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ const handleAppAction = (action) => {
appState = appState.setIn(['updates', 'lastCheckWOY'], dates.todayWOY())
appState = appState.setIn(['updates', 'lastCheckMonth'], dates.todayMonth())
appState = appState.setIn(['updates', 'firstCheckMade'], true)
if (!appState.getIn(['updates', 'weekOfInstallation'])) {
appState = appState.setIn(['updates', 'weekOfInstallation'], dates.lastMonday(new Date()))
}
break
case appConstants.APP_SET_UPDATE_STATUS:
if (action.status !== undefined) {
Expand Down
49 changes: 49 additions & 0 deletions test/unit/app/browser/datesTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* global describe, it, before, after */

const assert = require('assert')
const sinon = require('sinon')
let dates

require('../../braveUnit')

describe('update date handling', function () {
const exampleDate = 1510708981887 // Tuesday November 14th 2017, 6:23:01 PM
const exampleDate2 = 1512304291746 // Monday December 04th 2017, 9:18:11 AM
let fakeClock
before(function () {
fakeClock = sinon.useFakeTimers(exampleDate)
dates = require('../../../../app/dates')
})
after(function () {
fakeClock.restore()
})

describe('todayYMD', function () {
it('returns YYYY-MM-DD of today', function () {
assert.equal(dates.todayYMD(), '2017-11-14', 'today')
})
})

describe('todayWOY', function () {
it('returns the ISO week number for today', function () {
assert.equal(dates.todayWOY(), 314, 'ISO week number')
})
})

describe('todayMonth', function () {
it('returns the month of today as a number', function () {
assert.equal(dates.todayMonth(), 11, 'Month of today')
})
})

describe('lastMonday', function () {
it('returns YYYY-MM-DD of closest Monday in the past to current date', function () {
const d = new Date(exampleDate)
assert.equal(dates.lastMonday(d), '2017-11-13', 'previous Monday')
})
it('returns YYYY-MM-DD of today if today is monday', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aekeus here's the test I added regarding the previous comment

const d = new Date(exampleDate2)
assert.equal(dates.lastMonday(d), '2017-12-04', 'today is Monday')
})
})
})
7 changes: 5 additions & 2 deletions tools/buildPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ const isLinux = process.platform === 'linux'

var env = {
NODE_ENV: 'production',
CHANNEL: process.env.CHANNEL
CHANNEL: process.env.CHANNEL,
REF: process.env.REF || null
}

const channel = env.CHANNEL
const ref = env.REF

var channels = { nightly: true, developer: true, beta: true, dev: true }
if (!channels[channel]) {
Expand Down Expand Up @@ -75,7 +77,8 @@ config.writeBuildConfig(
{
channel: channel,
BROWSER_LAPTOP_REV: require('git-rev-sync').long(),
nodeEnv: env.NODE_ENV
nodeEnv: env.NODE_ENV,
ref: ref || null
},
'buildConfig.js'
)
Expand Down