Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change country_code to null when setting lat/long to 0/null #552

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 37 additions & 2 deletions core/streams/create.int.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,58 @@ describe('POST /streams', () => {
expect(stream.countryCode).toBe('GB')
})

test('country code is null for undefined lat', async () => {
test('country code is null and timezone is UTC for undefined lat', async () => {
const response = await request(app).post('/').send({ id: 'qwertyuiop40', name: 'my stream 4', latitude: undefined, longitude: -4.5 })

expect(response.statusCode).toBe(201)
const id = response.header.location.replace('/streams/', '')
const stream = await models.Stream.findByPk(id)
expect(stream.id).toBe('qwertyuiop40')
expect(stream.timezone).toBe('UTC')
expect(stream.countryCode).toBe(null)
})

test('country code is null for null lat', async () => {
test('country code is null and timezone is UTC for null lat', async () => {
const response = await request(app).post('/').send({ id: 'qwertyuiop40', name: 'my stream 4', latitude: null, longitude: -4.5 })

expect(response.statusCode).toBe(201)
const id = response.header.location.replace('/streams/', '')
const stream = await models.Stream.findByPk(id)
expect(stream.id).toBe('qwertyuiop40')
expect(stream.timezone).toBe('UTC')
expect(stream.countryCode).toBe(null)
})

test('country code is null and timezone is UTC for null lat long', async () => {
const response = await request(app).post('/').send({ id: 'qwertyuiop40', name: 'my stream 4', latitude: null, longitude: null })

expect(response.statusCode).toBe(201)
const id = response.header.location.replace('/streams/', '')
const stream = await models.Stream.findByPk(id)
expect(stream.id).toBe('qwertyuiop40')
expect(stream.timezone).toBe('UTC')
expect(stream.countryCode).toBe(null)
})

test('country code is null and timezone is UTC for 0 lat long', async () => {
const response = await request(app).post('/').send({ id: 'qwertyuiop40', name: 'my stream 4', latitude: 0, longitude: 0 })

expect(response.statusCode).toBe(201)
const id = response.header.location.replace('/streams/', '')
const stream = await models.Stream.findByPk(id)
expect(stream.id).toBe('qwertyuiop40')
expect(stream.timezone).toBe('UTC')
expect(stream.countryCode).toBe(null)
})

test('country code is null and timezone is UTC for 0 lat', async () => {
const response = await request(app).post('/').send({ id: 'qwertyuiop40', name: 'my stream 4', latitude: 0, longitude: -4.5 })

expect(response.statusCode).toBe(201)
const id = response.header.location.replace('/streams/', '')
const stream = await models.Stream.findByPk(id)
expect(stream.id).toBe('qwertyuiop40')
expect(stream.timezone).toBe('UTC')
expect(stream.countryCode).toBe(null)
})

Expand Down
1 change: 1 addition & 0 deletions core/streams/dao/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function computedAdditions (data, stream = {}) {
additions.countryCode = getCountryCodeByLatLng(latitude, longitude)
} else {
additions.timezone = 'UTC'
additions.countryCode = null
}
return additions
}
Expand Down
3 changes: 2 additions & 1 deletion core/streams/dao/index.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ describe('test computedAdditions function', () => {
test('return an empty object if lat or lng is undefined', async () => {
const additions = computedAdditions({ latitude: 54.2, longitude: undefined })
expect(additions).toStrictEqual({
timezone: 'UTC'
timezone: 'UTC',
countryCode: null
})
})
test('return expected result for the correct coordinates', async () => {
Expand Down
49 changes: 45 additions & 4 deletions core/streams/update.int.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('PATCH /streams/:id', () => {
expect(streamUpdated.countryCode).toBe('PL')
})

test('country code is not changed for undefined lat', async () => {
test('country code is changed to null and timezone is UTC for undefined lat', async () => {
const stream = { id: 'qwertyuiop40', name: 'my stream 4', latitude: 54.2, longitude: -4.5, timezone: 'Europe/Britain', countryCode: 'GB', createdById: seedValues.primaryUserId }
await models.Stream.create(stream)
await models.UserStreamRole.create({ stream_id: stream.id, user_id: stream.createdById, role_id: seedValues.roleOwner })
Expand All @@ -245,10 +245,11 @@ describe('PATCH /streams/:id', () => {
const response = await request(app).patch(`/${stream.id}`).send(requestBody)
expect(response.statusCode).toBe(204)
const streamUpdated = await models.Stream.findByPk(stream.id)
expect(streamUpdated.countryCode).toBe('GB')
expect(streamUpdated.timezone).toBe('UTC')
expect(streamUpdated.countryCode).toBeNull()
})

test('country code is not changed for null lat', async () => {
test('country code is changed to null and timezone is UTC for null lat', async () => {
const stream = { id: 'qwertyuiop40', name: 'my stream 4', latitude: 54.2, longitude: -4.5, timezone: 'Europe/Britain', countryCode: 'GB', createdById: seedValues.primaryUserId }
await models.Stream.create(stream)
await models.UserStreamRole.create({ stream_id: stream.id, user_id: stream.createdById, role_id: seedValues.roleOwner })
Expand All @@ -257,7 +258,47 @@ describe('PATCH /streams/:id', () => {
const response2 = await request(app).patch(`/${stream.id}`).send(requestBody)
expect(response2.statusCode).toBe(204)
const streamUpdated = await models.Stream.findByPk(stream.id)
expect(streamUpdated.countryCode).toBe('GB')
expect(streamUpdated.timezone).toBe('UTC')
expect(streamUpdated.countryCode).toBeNull()
})

test('country code is changed to null and timezone is UTC for null lat long', async () => {
const stream = { id: 'qwertyuiop40', name: 'my stream 4', latitude: 54.2, longitude: -4.5, timezone: 'Europe/Britain', countryCode: 'GB', createdById: seedValues.primaryUserId }
await models.Stream.create(stream)
await models.UserStreamRole.create({ stream_id: stream.id, user_id: stream.createdById, role_id: seedValues.roleOwner })

const requestBody = { latitude: null, longitude: null }
const response2 = await request(app).patch(`/${stream.id}`).send(requestBody)
expect(response2.statusCode).toBe(204)
const streamUpdated = await models.Stream.findByPk(stream.id)
expect(streamUpdated.timezone).toBe('UTC')
expect(streamUpdated.countryCode).toBeNull()
})

test('country code is changed to null and timezone is UTC for 0 lat long', async () => {
const stream = { id: 'qwertyuiop40', name: 'my stream 4', latitude: 54.2, longitude: -4.5, timezone: 'Europe/Britain', countryCode: 'GB', createdById: seedValues.primaryUserId }
await models.Stream.create(stream)
await models.UserStreamRole.create({ stream_id: stream.id, user_id: stream.createdById, role_id: seedValues.roleOwner })

const requestBody = { latitude: 0, longitude: 0 }
const response2 = await request(app).patch(`/${stream.id}`).send(requestBody)
expect(response2.statusCode).toBe(204)
const streamUpdated = await models.Stream.findByPk(stream.id)
expect(streamUpdated.timezone).toBe('UTC')
expect(streamUpdated.countryCode).toBeNull()
})

test('country code is changed to null and timezone is UTC for 0 lat', async () => {
const stream = { id: 'qwertyuiop40', name: 'my stream 4', latitude: 54.2, longitude: -4.5, timezone: 'Europe/Britain', countryCode: 'GB', createdById: seedValues.primaryUserId }
await models.Stream.create(stream)
await models.UserStreamRole.create({ stream_id: stream.id, user_id: stream.createdById, role_id: seedValues.roleOwner })

const requestBody = { latitude: 0, longitude: -4.5 }
const response2 = await request(app).patch(`/${stream.id}`).send(requestBody)
expect(response2.statusCode).toBe(204)
const streamUpdated = await models.Stream.findByPk(stream.id)
expect(streamUpdated.timezone).toBe('UTC')
expect(streamUpdated.countryCode).toBeNull()
})

test('country code is null for coordinates somewhere in the ocean', async () => {
Expand Down
Loading