* window.ForemMobile namespaced functions * Fix broken Buildkite * Wait for data-loaded before using Runtime in pack * Bring back sprockets base * Better error handling * Smal fixes to ConsumerApp to support Android platform * Fix typo * utilities/waitForDataLoaded.js * Update app/javascript/utilities/waitForDataLoaded.js Co-authored-by: Nick Taylor <nick@forem.com> * Review feedback * Fix failing spec * Cleanup promise * Remove old utility file * Add Cypress check for namespaced availability * More specs * Refactor to rely on ForemMobile for native bridge messaging * Fix spec/requests/api/v0/instances_spec.rb * Fix devices spec * Remove changes to /api/instance * Refactor to dynamic import * Fix typo * Fixed custom event detail payload for tests. * mock ForemMobile function instead of webkit call directly * failing jest test debug * Another attempt * Fixed broken test that was missing an onMainImageUrlChange prop on the component. * Fixed mobile bridging E2E tests. * Move Cypress tests to mobileFlows * Add JSDocs + cypress spec for injectJSMessage when logged out * Cleanup + Disable native image upload until AppStore approval Co-authored-by: Nick Taylor <nick@forem.com> Co-authored-by: Nick Taylor <nick@dev.to>
93 lines
2.4 KiB
Ruby
93 lines
2.4 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Devices", type: :request do
|
|
let(:user) { create(:user) }
|
|
let(:consumer_app) { create(:consumer_app) }
|
|
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
describe "POST /users/devices" do
|
|
context "when device persisted" do
|
|
it "increases device count" do
|
|
post devices_path, params: {
|
|
token: "123",
|
|
platform: "ios",
|
|
app_bundle: consumer_app.app_bundle
|
|
}
|
|
expect(user.devices.count).to eq(1)
|
|
expect(response).to have_http_status(:created)
|
|
end
|
|
end
|
|
|
|
context "when device not persisted" do
|
|
let(:params) do
|
|
{
|
|
token: "123",
|
|
platform: "unknown",
|
|
app_bundle: consumer_app.app_bundle
|
|
}
|
|
end
|
|
|
|
it "does not increase device count" do
|
|
post devices_path, params: params
|
|
expect(user.devices.count).to eq(0)
|
|
end
|
|
|
|
it "returns an error" do
|
|
post devices_path, params: params
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
expect(response.body).to include("error")
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "DELETE /users/devices/:id" do
|
|
let(:device) { create(:device, user: user) }
|
|
|
|
context "when device not found" do
|
|
let(:incomplete_params) do
|
|
{
|
|
platform: device.platform,
|
|
app_bundle: device.consumer_app.app_bundle
|
|
}
|
|
end
|
|
|
|
it "returns an error" do
|
|
delete device_path(123)
|
|
|
|
expect(response.status).to eq(404)
|
|
expect(response.parsed_body["error"]).to eq("Not Found")
|
|
expect(response.parsed_body["status"]).to eq(404)
|
|
end
|
|
|
|
it "return an error if device id doesn't match params" do
|
|
delete device_path(123), params: incomplete_params
|
|
|
|
expect(response.status).to eq(404)
|
|
expect(response.parsed_body["error"]).to eq("Not Found")
|
|
expect(response.parsed_body["status"]).to eq(404)
|
|
end
|
|
end
|
|
|
|
context "when device deleted" do
|
|
let(:params) do
|
|
{
|
|
token: device.token,
|
|
platform: device.platform,
|
|
app_bundle: device.consumer_app.app_bundle
|
|
}
|
|
end
|
|
|
|
it "deletes the device" do
|
|
delete device_path(device.user.id), params: params
|
|
|
|
expect(user.devices.count).to eq(0)
|
|
expect(response.status).to eq(204)
|
|
expect(Device.find_by(id: device.id)).to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|