Skip to content

Commit f8fd7c1

Browse files
author
Hidetaka Okamoto
committed
feat: update default attributes
1 parent 48961d4 commit f8fd7c1

File tree

3 files changed

+49
-45
lines changed

3 files changed

+49
-45
lines changed

src/PersistentAttributesManager/PersistentAttributesManager.service.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class PersistentAttributesManager<
3434
private static instance: PersistentAttributesManager;
3535
private readonly logger: Logger = new DefaultLogger();
3636
private hasUpdated: boolean = false;
37-
protected readonly defaultAttributes?: T = undefined
37+
protected readonly defaultAttributes?: T = undefined;
3838

3939
public static getInstance<
4040
T extends PersistentAttributes = PersistentAttributes
@@ -50,7 +50,9 @@ export class PersistentAttributesManager<
5050
this.attributeManager = attributesManager;
5151
}
5252

53-
public async getPersistentAttributes(defaultAttributes?: Partial<T>): Promise<T> {
53+
public async getPersistentAttributes(
54+
defaultAttributes?: Partial<T>
55+
): Promise<T> {
5456
try {
5557
const data = await this.attributeManager.getPersistentAttributes();
5658
if (data) {
@@ -60,7 +62,7 @@ export class PersistentAttributesManager<
6062
...data,
6163
} as T;
6264
this.attributeManager.setPersistentAttributes(item);
63-
return item
65+
return item;
6466
}
6567
} catch (e) {
6668
this.logger.debug(e.name);
@@ -69,9 +71,9 @@ export class PersistentAttributesManager<
6971
const defaultAtts = {
7072
...this.defaultAttributes,
7173
...defaultAttributes,
72-
} as T
74+
} as T;
7375
this.attributeManager.setPersistentAttributes(defaultAtts);
74-
return defaultAtts
76+
return defaultAtts;
7577
}
7678

7779
/**
@@ -87,7 +89,9 @@ export class PersistentAttributesManager<
8789
* await persistentAttributesManager.save()
8890
* ```
8991
*/
90-
public async updatePersistentAttributes(attributes: Partial<T>): Promise<void> {
92+
public async updatePersistentAttributes(
93+
attributes: Partial<T>
94+
): Promise<void> {
9195
try {
9296
const data = await this.attributeManager.getPersistentAttributes();
9397
this.attributeManager.setPersistentAttributes(

src/PersistentAttributesManager/__tests__/PersistanteAttributesManager.service.spec.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,83 +47,83 @@ describe('PersistenteAttributesManager.service.ts', () => {
4747
type TestTypes = {
4848
name: string;
4949
count: number;
50-
}
50+
};
5151
class ExtendClass extends PersistentAttributesManager<TestTypes> {
5252
protected readonly defaultAttributes = {
5353
name: 'john',
54-
count: 0
55-
}
54+
count: 0,
55+
};
5656
}
57-
let target: ExtendClass
57+
let target: ExtendClass;
5858
beforeEach(() => {
5959
adapter = new MockPersistenceAdapter();
6060
handlerInput = new HandlerInputFactory(
6161
new RequestEnvelopeFactory(new LaunchRequestFactory())
6262
)
6363
.setPersistanceAdapter(adapter)
6464
.create();
65-
target = new ExtendClass(handlerInput.attributesManager)
66-
})
65+
target = new ExtendClass(handlerInput.attributesManager);
66+
});
6767
it('should get default value', async () => {
68-
const attributes = await target.getPersistentAttributes()
68+
const attributes = await target.getPersistentAttributes();
6969
expect(attributes).toEqual({
7070
name: 'john',
71-
count: 0
72-
})
73-
})
71+
count: 0,
72+
});
73+
});
7474
it('should get overwritten default value', async () => {
7575
const attributes = await target.getPersistentAttributes({
76-
count: 2
77-
})
76+
count: 2,
77+
});
7878
expect(attributes).toEqual({
7979
name: 'john',
80-
count: 2
81-
})
82-
})
80+
count: 2,
81+
});
82+
});
8383
it('should get overwritten default value', async () => {
8484
const attributes = await target.getPersistentAttributes({
85-
count: 2
86-
})
85+
count: 2,
86+
});
8787
expect(attributes).toEqual({
8888
name: 'john',
89-
count: 2
90-
})
91-
})
89+
count: 2,
90+
});
91+
});
9292
it('should not saved default atts when does not call save', async () => {
9393
handlerInput2 = new HandlerInputFactory(
9494
new RequestEnvelopeFactory(new LaunchRequestFactory())
9595
)
9696
.setPersistanceAdapter(adapter)
9797
.create();
98-
const target2 = new ExtendClass(handlerInput2.attributesManager)
98+
const target2 = new ExtendClass(handlerInput2.attributesManager);
9999
await target.getPersistentAttributes({
100-
count: 2
101-
})
102-
const attributes = await target2.getPersistentAttributes()
100+
count: 2,
101+
});
102+
const attributes = await target2.getPersistentAttributes();
103103
expect(attributes).toEqual({
104104
name: 'john',
105-
count: 0
106-
})
107-
})
105+
count: 0,
106+
});
107+
});
108108
it('should saved default atts when call save', async () => {
109109
handlerInput2 = new HandlerInputFactory(
110110
new RequestEnvelopeFactory(new LaunchRequestFactory())
111111
)
112112
.setPersistanceAdapter(adapter)
113113
.create();
114-
const target2 = new ExtendClass(handlerInput2.attributesManager)
115-
const att =await target.getPersistentAttributes({
116-
count: 2
117-
})
118-
await target.updatePersistentAttributes(att)
119-
await target.save()
120-
const attributes = await target2.getPersistentAttributes()
114+
const target2 = new ExtendClass(handlerInput2.attributesManager);
115+
const att = await target.getPersistentAttributes({
116+
count: 2,
117+
});
118+
await target.updatePersistentAttributes(att);
119+
await target.save();
120+
const attributes = await target2.getPersistentAttributes();
121121
expect(attributes).toEqual({
122122
name: 'john',
123-
count: 2
124-
})
125-
})
126-
})
123+
count: 2,
124+
});
125+
});
126+
});
127127

128128
describe('Class method test', () => {
129129
it('| should not save adn get persisted attributes without execute save method', async () => {

src/framework/__tests__/SkillFactory.class.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,4 @@ describe('SkillFactoryr', () => {
260260
});
261261
});
262262
});
263-
});
263+
});

0 commit comments

Comments
 (0)