Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/app/confirmschool/confirmschool.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RouterTestingModule } from '@angular/router/testing';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core';
import { Network } from '@awesome-cordova-plugins/network/ngx';
import { ConfirmschoolPage } from './confirmschool.page';
import { DatePipe } from '@angular/common';

Expand All @@ -12,13 +13,21 @@ describe('ConfirmschoolPage', () => {
let fixture: ComponentFixture<ConfirmschoolPage>;

beforeEach(waitForAsync(() => {
// ConfirmschoolPage's constructor reads applicationLanguage synchronously;
// seed it so component creation doesn't throw in a fresh test environment.
localStorage.setItem(
'savedSettings',
JSON.stringify({ applicationLanguage: { code: 'en', label: 'English' } })
);

TestBed.configureTestingModule({
declarations: [ConfirmschoolPage],
imports: [IonicModule.forRoot(),
RouterTestingModule,
TranslateModule.forRoot()],
providers: [
DatePipe,
Network,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
Expand All @@ -34,6 +43,7 @@ describe('ConfirmschoolPage', () => {
});

afterEach(() => {
localStorage.removeItem('savedSettings');
TestBed.resetTestingModule();
});
});
43 changes: 40 additions & 3 deletions src/app/confirmschool/confirmschool.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NetworkService } from '../services/network.service';

import { School } from '../models/models';
import { Device } from '@capacitor/device';
import { App } from '@capacitor/app';
import { DatePipe } from '@angular/common';
import { environment } from 'src/environments/environment';
import { SettingsService } from '../services/settings.service';
Expand Down Expand Up @@ -131,7 +132,26 @@ export class ConfirmschoolPage implements OnInit{
this.schoolService
.registerSchoolDevice(schoolData)
.subscribe((response) => {
this.storage.set('deviceType', a.operatingSystem);
if (a.operatingSystem) {
this.storage.set('deviceType', a.operatingSystem);
}
if (a.name) {
this.storage.set('deviceName', a.name);
}
if (a.model) {
this.storage.set('deviceModel', a.model);
}
if (a.manufacturer) {
this.storage.set('deviceManufacturer', a.manufacturer);
}
if (a.osVersion) {
this.storage.set('osVersion', a.osVersion);
}
this.getAppBuildNumber().then((buildNumber) => {
if (buildNumber) {
this.storage.set('appBuildNumber', buildNumber);
}
});
this.storage.set('macAddress', b.identifier);
this.storage.set('schoolUserId', response);
this.storage.set('schoolId', this.schoolId);
Expand Down Expand Up @@ -229,8 +249,25 @@ export class ConfirmschoolPage implements OnInit{
}

async getDeviceInfo() {
const info = await Device.getInfo();
return info;
try {
const info = await Device.getInfo();
return info;
} catch (error) {
console.log('Error getting device info:', error);
// Fall back to an empty object so callers can safely read properties
// (e.g. a.osVersion) without the whole registration flow breaking.
return {} as any;
}
}

async getAppBuildNumber() {
try {
const info = await App.getInfo();
return info.build;
} catch (error) {
// Not available on this platform (e.g. web/Electron).
return null;
}
}

async getIPAddress() {
Expand Down
24 changes: 24 additions & 0 deletions src/app/services/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ export class UploadService {
giga_id_school: '',
app_version: environment.app_version,
};

// Device info is optional: only include a field if a value is actually
// available, rather than sending empty strings for unknown devices.
const deviceName = this.storage.get('deviceName');
if (deviceName) {
measurement['device_name'] = deviceName;
}
const deviceModel = this.storage.get('deviceModel');
if (deviceModel) {
measurement['device_model'] = deviceModel;
}
const deviceManufacturer = this.storage.get('deviceManufacturer');
if (deviceManufacturer) {
measurement['device_manufacturer'] = deviceManufacturer;
}
const appBuildNumber = this.storage.get('appBuildNumber');
if (appBuildNumber) {
measurement['app_build_number'] = appBuildNumber;
}
const osVersion = this.storage.get('osVersion');
if (osVersion) {
measurement['os_version'] = osVersion;
}

if (record.hasOwnProperty('accessInformation')) {
let clientInfo = record.accessInformation;

Expand Down